$(document).ready(function() {			
	
	//------ Add a class to JS enabled pages
	$("body").addClass("jsEnabled");
	
	if(navigator.userAgent.match(/iPhone/i)) {
	    $("body").addClass("iphone");
	}
	
	//------------------------------------------------------
	//-- LOGO AS HOME-STATE BUTTON		
		$('h1 img').click(function(){
			$(window).scrollTop(0);
			$('.panelContent_readMore').removeClass('panelActive').hide();
			$('.logoNavWrapper li.active').removeClass("active");
			//also reset the "Open/Close" button text!
			$('.openSection').text('Open +');
			$('.panelOverlay a').css('visibility','visible');
			return false;
		});
		
	//------------------------------------------------------
	//-- NAVIGATION
		//$('.logoNavWrapper li#hero1').addClass("active");
		$('.logoNavWrapper li').click(function(){
			
			$('.logoNavWrapper li.active').removeClass("active");
			$(this).addClass('active').blur();
			//initialise the section open script here if neccessary
			
		});
	
	//------------------------------------------------------
	//-- PRINT ARTICLE BUTTON
		//------ Append print wrapper
		$('body').append('<div id="printContent"><img height="22" width="300" alt="Allen &amp; Overy" src="_assets/images/siteLogo.gif"><span class="siteTitle">Annual Review 2011</span><br /><div class="pageContent"><!-- --></div></div>');
	
		$(".print").click(function(e){
			e.preventDefault();
			$('#printContent .pageContent').empty();
			
			//$('h1 img, .siteTitle').clone(false).appendTo($('#printContent'));
			
			var $sectionOne = $(this).parents('.section1MainContent');
			var $sectionTwo = $(this).parents('.section2Content');
			var $sectionOthers = $(this).parents('.panelContent_readMore'); 
			var $printArea = $('#printContent .pageContent');
			
			if ($(this).parents().is('.section1MainContent')){
				$sectionOne.find('.panelContent_readMore_col1A').addClass('sc1');
				//section 1 : only print the second part
				$sectionOne.parent().prev().find('h2').clone(false).appendTo($printArea);
				var thisSectionHeading = $sectionOne.find('.panelContent_readMore_col1 h3').text();
				$printArea.append('<h2 class="h3style">' + thisSectionHeading + '</h2>');
				var thisSectionContent = $sectionOne.find('.panelContent_readMore_col1, .panelContent_readMore_col1A');				
				$(thisSectionContent).clone(false).appendTo($printArea);
				
			} else if ($(this).parents().is('.section2Content')){
				$sectionTwo.find('.panelContent_readMore_col1A').addClass('sc2');
				//section 2 : only print the current tab content
				var thisTabContent = $sectionTwo.find('.squareTabContent.open');
				var thisSectionHeading = $(this).parents('.panel').find('h2');
				$printArea.append(thisSectionHeading);
				$(thisTabContent).clone(false).appendTo($printArea);
				
			} else {
				//other sections
				var thisSectionHeading = $sectionOthers.find('.panelContent_readMore_col1 h3').text();
				$printArea.append('<h2>' + thisSectionHeading + '</h2>');
				var thisSectionMain = $sectionOthers.find('.panelContent_readMore_col1, .panelContent_readMore_col1A');
				$(thisSectionMain).clone(false).appendTo($printArea);
			}
			
			var copyrightText = $('.copyright').text();
			$printArea.append('<p class="copyright">' + copyrightText + '</p>');
			
			$('#wrapper').addClass('noPrint');
			//return false;
			window.print();
		});
		

	//------------------------------------------------------			
	//-- SQUARE TABS
	$('.squareTabContent').hide(); 
		$('.squareTabs li:first').addClass('active').show(); //Activate first tab
		$('.squareTabContent:first').show().addClass('open'); //Show first tab content
		//Click Event
		$('.squareTabs li').click(function() {
	
			$('.squareTabs li').removeClass('active'); //Remove any "active" class
			$(this).addClass('active'); //Add "active" class to selected tab
			Cufon.refresh('.innerTabsWrapper .squareTabs li.active h3');
			$('.squareTabContent').hide().removeClass('open'); //Hide all tab content
			
			var activeTab = $(this).find('div').attr('class'); //Find the class attribute value (e.g. #tab3) store it in the variable 'activeTab'
			$(activeTab).show().addClass('open'); //show the active ID content
			return false;
		});


	//------------------------------------------------------			
	//-- DOWNLOADS DROPDOWN
	
	
	$('body').addClass('dropdownClosed');
	$('.dlDropdownWrap').addClass('isClosed');
	$('.dlDropdown').css('height','0px');
	
	var downloadsBox = {}
	downloadsBox.closebox = function(){
		$('.headerWrapper').animate({top: '0px'}, 400);
		$('.dlDropdown').animate({height: '0px'}, 400);
		$('#scroller').animate({paddingTop: '180px'}, 400);
		$('body').addClass('dropdownClosed');
		$('.dlDropdownWrap').addClass('isClosed');
		$('.openDropdownBtn').text('Download Reports +');	
	}
	downloadsBox.openbox = function(){
		$('.headerWrapper').animate({top: '250px'}, 400);
		$('.dlDropdown').animate({height: '250px'}, 400);
		$('#scroller').animate({paddingTop: '430px'}, 400);
		$('body').removeClass('dropdownClosed');
		$('.dlDropdownWrap').removeClass('isClosed');
		$('.openDropdownBtn').text('Download Reports -');	
		$('.logoNavWrapper li').removeClass("active");
	}
	
	$('.openDropdownBtn').click(function(e){
		e.preventDefault();
		var dlClosedState = $('body').hasClass('dropdownClosed');
		if (dlClosedState){
			downloadsBox.openbox();
		}else{
			downloadsBox.closebox();
			//$('#scroller').animate({paddingTop: '180px'}, 400);
		}
		
	});
	
	$('.closeDropdownBtn').click(function(e){
		e.preventDefault();
		downloadsBox.closebox();
	});
	
	
	//------------------------------------------------------			
	//-- JUMP LINKS (Open section and scroll to target)
	$('a.opener').click(function(){
		var targetSection = $(this).attr('href'); //#section4
		var scrollToPos = $(targetSection).offset();
		$(window).scrollTop(scrollToPos.top - 190);
		
		//open section
		var targetSectionContent = $(targetSection).next().find('.panelContent_readMore').addClass('panelActive');
		//$(targetSection).next().find('.panelContent_readMore').show();
		$(targetSectionContent).show(function(){
			$(this).prev().find('.openSection').text('Close -');
			$(this).prev().find('.panelOverlay a').css('visibility','visible');
		});
		
			//$currentSection.find('.openSection').text('Open +');
			//$currentSection.find('.panelOverlay a').css('visibility','visible');	
		
		return false;
		
	});
	
			
}); //close document.ready


