
// onload standard function
$(document).ready(function()  
{  

	// hide the page if IE to stop page flicker
	if(jvars.browserType == 'Internet Explorer')
	{
		// hide
		//$("body").css("display", "none");
		// show
		//$("body").fadeIn(1);
		
		// bind the exit event
		////$(window).bind('beforeunload', function(){ 
			// provide transition for exit
		////	$("body").fadeOut(2000);
		////});
		
		$(window).unload(function(){
		   ////$("body").fadeOut(2000);
		 });
	}
	
	// load proper css file before initiating code | this will trump existing style declarations
	if(jvars.platformType=='iPad' || jvars.platformType=='iPhone') {
		
		//$("head").append($("<link rel='stylesheet' href='styles/hoverbar_mobile.css' type='text/css' media='screen' />"));
		
		$("head").append("<link>");
		css = $("head").children(":last");
		css.attr({
		  rel:  "stylesheet",
		  type: "text/css",
		  href: "styles/hoverbar_mobile.css"
		});
		
		/*
		$("<link>").appendTo("head")({
			 rel: 'stylesheet',
			 type: 'text/css',
			 href: 'styles/hoverbar_mobile.css'
		});
		*/
		
		// because it might take a moment for the new css to load, change the existing style
		// attributes. We use a condition to be sure.
		if( $("#baseBar").length )
		{
			$("#baseBar").css({position:'absolute'});
			
			// we also use an IE6 fix in the css but that is irrelevant for this code since
			// the iPad and iPhone do not use IE
		}

		// monitor footer
		initiateFooterToBaselineAnchor();
	
	 } else {
		 
		// already loaded as part of page header
		/*
		 $("head").append("<link>");
		css = $("head").children(":last");
		css.attr({
		  rel:  "stylesheet",
		  type: "text/css",
		  href: "js/hoverbar.css"
		});
		*/
		
	 }
	 
	 // this is only called if the mobile css was loaded
	 function initiateFooterToBaselineAnchor() 
	 {
		
		// Calculate footer placement if we are on ipad or iphone (they don't use fixed position)
		if( $("#baseBar").length )
		{
			if(jvars.platformType=='iPad' || jvars.platformType=='iPhone')
			{	
				// begin monitor
				jQuery.anchorFooterToBaseline();
			}
		}
		
	 }
	 
	//if(scroller)scroller  = new jsScroller(document.getElementById("GCR-content_AboutCopy"), 300, 450);
  	//if(scrollbar)scrollbar = new jsScrollbar (document.getElementById("Scrollbar-Container"), scroller, true, scrollbarEvent);
	
	
	/* Calculate the center of page */
	//jQuery.centerall();
	
	// watch footer position
	if( $("#baseBar").length )
	{
	//	jQuery.preventFooterOverContent();
	}
	
	
	
	/* Reveal page */
	//$("#Table_01").show("slow");
	/**/
	
	// removed
	function resizeDIV() {
		var $window = jQuery(window);
		var $table = jQuery("#Table_01");
		//var tableX = $("#Table_01").css("left").replace("px", "");
		
		//if ($window.width() < $table.width()) {
		if ($window.width() < 1325) {
				var adjustedX = Number( 0 - ($table.width() - $window.width()) );
				if (adjustedX <= -101)
				{
					adjustedX = -100;
					//$('#Table_01').animate({ left: adjustedX },400,function() { makeLeftPropertyStick(adjustedX) });
					
					makeLeftPropertyStick(adjustedX);
				} else {
					
					//makeLeftPropertyStick(adjustedX);
					
				}
		} else {
			//$('#Table_01').animate({ left: 0 },400,function() { makeLeftPropertyStick(0) });
			makeLeftPropertyStick(0);
		}
	}
	function makeLeftPropertyStick(adjustedX) {
	
		$('#Table_01').css({
			left: adjustedX + "px"
		});
		
	}
	
	
	
	
	// Initial call to resize DIV.
    //resizeDIV();
	
	/*
	jQuery(window).bind("resize", function() {
            resizeDIV();  
        })
	*/
		
}); 


$(function(){
	
	
		
});

$(function(){
  // Bind the resize event to the plugin. This is required for FireFox, but works
  // for all other browsers, so it is being used for browser compatibility.
  
	$(window).resize(function() {

		/* Calculate the center of page */
		//jQuery.centerall();
		
		/* Calculate footer placement if we are on ipad or iphone (they don't use fixed position)*/
		if( $("#baseBar").length )
		{
			if(jvars.platformType=='iPad' || jvars.platformType=='iPhone')
				jQuery.anchorFooterToBaseline();
		}

		// watch footer position
		//if( $("#baseBar").length )
		//	jQuery.preventFooterOverContent();
		
		//resizeDIV();
		
	});	
	$(window).scroll(function() {

		// watch footer position
		//if( $("#baseBar").length )
		//	jQuery.preventFooterOverContent();
		
		/* Calculate footer placement if we are on ipad or iphone (they don't use fixed position)*/
		if( $("#baseBar").length )
		{
			if(jvars.platformType=='iPad' || jvars.platformType=='iPhone')
				jQuery.anchorFooterToBaseline();
		}

	});	
		
});

$(function()
{

	var selectedCategoryButton = null;
	var selectedCategoryButtonId = null;
	var selectedResourceId; //  = 'GCR-contentResource_Architects'
	
	$('div.printcopy_contacts_label_handcursor').live('click', function(e) {
		
		var link = $(this).attr("link");
		
		if(link=="team")
		{
			//$("#CONTACT-SPECIFIC").animate( { height: $('#GCR-webLayoutFinal-MainHTMLreSliced015_contactIndex').css('height') }, 695 );
			
			//$("GCR-webLayoutFinal-MainHTMLreSliced015_contactIndex").animate({height:695}, 1000, "linear", function(){} );
			$("#CONTACT-SPECIFIC_LIST").animate({height:655}, 750, "linear", function(){} );

			//event.preventDefault();
			/*
			$('#GCR-webLayoutFinal-MainHTMLreSliced015_contactIndex').hide();
			$('#CONTACT-SPECIFIC_displayindex').hide();
			$("#GCR-footerElement10b").hide(); // hide the footer for now
			$('#CONTACT-SPECIFIC_displaylist').show();
			$('#GCR-webLayoutFinal-MainHTMLreSliced015_contactList').show();
			*/
		} else {
			$("#CONTACT-SPECIFIC_LIST").animate({height:0}, 750, "linear", function(){} );
			/*
			$('#GCR-webLayoutFinal-MainHTMLreSliced015_contactList').hide();
			$('#CONTACT-SPECIFIC_displaylist').hide();
			$("#GCR-footerElement10b").show();
			$('#CONTACT-SPECIFIC_displayindex').show();
			$('#GCR-webLayoutFinal-MainHTMLreSliced015_contactIndex').show();
			*/
		}
	});
	
	$('img.useHandCursor').hover(function()
	{
		  var exception = $(this).attr("exception");
		  if(exception=="hoveroff")return;
		  
		  $(this).attr("src", $(this).attr("src").replace("_off.", "_on."));
		  
		  if($(this).attr("name")=="portfolio")
		  	$('#menu').show();
		  else
		  	$('#menu').hide();
		  	
	}, function() {
		  var exception = $(this).attr("exception");
		  if(exception=="hoveroff")return;
		
		  // do not remove rollover from selected button
		  if(!selectedCategoryButtonId || selectedCategoryButtonId != $(this).attr("cat"))
		  	$(this).attr("src", $(this).attr("src").replace("_on.", "_off."));
	});
	// USE MOUSE EVENTS INSTEAD OF HOVER when LIVE event is necessary
	$('img.isLiveButton').live('mouseenter', function (e) { 
			
		  var exception = $(this).attr("exception");
		  if(exception=="hoveroff")return;
		  
		  $(this).attr("src", $(this).attr("src").replace("_off.", "_on."));
		  
		  if($(this).attr("name")=="portfolio")
		  	$('#menu').show();
		  else
		  	$('#menu').hide();	 
	
	}).live('mouseleave', function (e) { 
								  
	  	  var exception = $(this).attr("exception");
		  if(exception=="hoveroff")return;
		
		  // do not remove rollover from selected button
		  if(!selectedCategoryButtonId || selectedCategoryButtonId != $(this).attr("cat"))
		  	$(this).attr("src", $(this).attr("src").replace("_on.", "_off."));		
	});
	$('.navButton').live('click', function(e) {
		
		var id = $(this).attr("cat");
		var page = $(this).attr("page");
		
		if(id!=undefined) {
			// go to specified page if both id and page are defined
			if(page!=undefined){
				window.location = page+"?page="+id;
			} else // send direct call via ajax if we only have an id	
				getCategoryData(id);
		} else {
			// id does not exist; navigate to page
			if(page!=undefined)
				window.location = page;
		}
	
	});
	/*
	$('img.useHandCursor').live('click', function(e) {
		
		// reset the selected button if valid
		if(selectedCategoryButton)selectedCategoryButton.attr("src", selectedCategoryButton.attr("src").replace("_on.", "_off."));	
			
		var id = $(this).attr("cat");
		var page = $(this).attr("page");
		
		// update the selected button var
		selectedCategoryButtonId = id;
		selectedCategoryButton = $(this);
		
		if(id!=undefined) {
			// go to specified page
			if(page!=undefined){
				window.location = page+"?page="+id;
			} else // send direct call since id is valid	
				if(jvars.platformType=='iPad' || jvars.platformType=='iPhone')
					getCategoryData(id);			
				else
					getCategoryData(id);
					//SendDataToFlex(id,'catSelect');
		} else {
			// id does not exist; navigate to page
			if(page!=undefined)
				window.location = page;
		}

	});
	*/

	$('span.useHandCursor_resource').live('click', function(e) {

		var id = $(this).attr("cat");
		var name = $(this).attr("name");
		
		if(name!=undefined) {
			
			if(selectedResourceId)
			{
				// hide the existing category; independent of the number of columns
				$("[id^='resourcesection_"+selectedResourceId+"']").hide();
				
				// remove highlight from category menu
				$("[id='ajaxmenu']" && "[name='"+selectedResourceId+"']").removeClass('ajaxmenu_on');
		
			} else {
				// initially, turn off all columns to be sure we hide the one that loaded with the page
				$('[id^="resourcesection_"]').hide();
				
				// remove highlight from all category menus
				$('[id^="ajaxmenu"]').removeClass('ajaxmenu_on');	
			}

			selectedResourceId = name;
			
			// show the selected category; independent of the number of columns
			$("[id^='resourcesection_"+selectedResourceId+"']").show();
			
			// highlight the selected category menu
			$("[id='ajaxmenu']" && "[name='"+selectedResourceId+"']").addClass('ajaxmenu_on');
		
			
		} else {
			// do nothing
		}
	});
	// FOR RESOURCES PAGE
	$('span.useHandCursor_resource').hover(function()
	{
		  $(this).css({color:'#F7982A'});

	}, function() {

		  // make sure to give the proper color to the selected item
		  var id = $(this).attr("cat");
		  if(id==selectedResourceId){
		  	$(this).css({color:'#BE7842'});
		  }else{
		  	$(this).css({color:'#5c4f46'});
		  }
	});
	
	$('a.mediaRollover').hover(function()
	{
	  
		  // get the source where we show the preview	  
		  var str_url1 = $('#media_preview').attr("src");		  
		  intPos = str_url1.lastIndexOf("/");
		  
		  // get the path
		  var path = str_url1.substring(0, intPos);

		  // get the source of the selected file & set thumbnail extension
		   var str_url2 = $(this).attr("href").replace(".jpg", ".png");

		  // get the file name
		  var filename =  str_url2.match(/[-_\w]+[.][\w]+$/i)[0];

		  // set the thumbs directory and new thumbnail
		  source = path + "/" + filename; // source.replace('ads','ads/thumbs');
		  
		  // set new source for preview
		  $('#media_preview').attr("src", source);
		  
		  //href="./docs/media/ads/SBMagJanFeb_2009.jpg"

		  	
	}, function() {

		  //
	});

	// FOR CONTACTS PAGE
	$('div.printcopy_contacts_label_handcursor').hover(function()
	{
		  $(this).css({color:'#F7982A'});

	}, function() {

		  $(this).css({color:'#5c4f46'}); 
	});


	$('#menu').hover(function()
	{
		  
	}, function() {
		  
		  $('#menu').hide();
	});
	// USE MOUSE EVENTS INSTEAD OF HOVER when LIVE event is necessary
	$('#menu.isLive').live('mouseenter', function (e) { 

	
	}).live('mouseleave', function (e) { 
								  
	  	  $('#menu').hide();	
	});
	
	/*
	$('div.spanmenu').hover(function()
	{
		  $(this).css('background-image', 'url(./graphics/77pct_white_1px.png)'); //90pct_white_1px.png background-image: url(../graphics/bkg70pctBlk.png);
		  $(this).css('color', '#000');
	}, function() {
		  $(this).css('background-image', '');
		  $(this).css('color', '#FFF');
	});
	*/
	$('div.spanmenu').live('mouseenter', function (e) { 

		$(this).css('background-image', 'url(./graphics/77pct_white_1px.png)'); //90pct_white_1px.png background-image: url(../graphics/bkg70pctBlk.png);
		$(this).css('color', '#000');
	}).live('mouseleave', function (e) { 
		$(this).css('background-image', '');
		$(this).css('color', '#FFF');	
	});

	$('div.spanmenu').live('click', function(e) {
		
		// reset the selected button if valid
		if(selectedCategoryButton)selectedCategoryButton.attr("src", selectedCategoryButton.attr("src").replace("_on.", "_off."));	
		
		$('#menu').hide();
		var id = $(this).attr("cat");
		var page = $('#menu').attr("page");

		if(id!=undefined) {
			// go to specified page
			if(page!=undefined){
				window.location = page+"?page="+id;
			} else { // send direct call since id is valid	
				if(jvars.platformType=='iPad' || jvars.platformType=='iPhone')
					getCategoryData(id);			
				else
					getCategoryData(id);
					//SendDataToFlex(id,'catSelect');
			}
		} else {
			// id does not exist; navigate to page
			if(page!=undefined)
				window.location = page;
		}
		
		// update the selected button var if still on page
		selectedCategoryButtonId = id;
		var group = $(this).attr("group");
		if(group)
		{
			selectedCategoryButton = $('#'+group);
			if(selectedCategoryButton)selectedCategoryButton.attr("src", selectedCategoryButton.attr("src").replace("_off.", "_on."));
		}

		
	});
	
	
});


// Transition functions
$(function() {
	
		$.OLD_makeImageTransition_OLD = function (tObectId) {

			//alert(jtransition.arr[tObectId]['numOfTransitionSections']);
			
			// reference current selection before applying new
			var old_selection = jtransition.arr[tObectId]['gCurrentTransitionSection'];
			
			
			
			// //get the next image
			jtransition.arr[tObectId]['gCurrentTransitionSection']++; 
			
			// confirm the selection
			if(jtransition.arr[tObectId]['gCurrentTransitionSection']<1) // evaluate less than 0
				jtransition.arr[tObectId]['gCurrentTransitionSection'] = jtransition.arr[tObectId]['numOfTransitionSections']; // give hightest count	
			else if(jtransition.arr[tObectId]['gCurrentTransitionSection']>jtransition.arr[tObectId]['numOfTransitionSections']) 
				jtransition.arr[tObectId]['gCurrentTransitionSection'] = 1; // give lowest number
			

			// give the new selection the next z-order below the visible image
			$("[id='imgTransition']" && "[transitionselection='"+jtransition.arr[tObectId]['gCurrentTransitionSection']+"']").css('zIndex', 115);
			// make the new image visible, but keep it below the stack order so the fade will be smooth
			/*
			* Keep in mind, it's important to bring the image back into display mode. The initial load
			* configures the image to be displayed by simply adjusting the Z order. After that, it is
			* turned off (that is, when another image is clicked and takes its place on the stage. So on
			* the second time around, the image must be turned back on. Just make sure the statement that
			* follows actually turns on the image. SHOW was giving trouble.
			*/
			$("[id='imgTransition']" && "[transitionselection='"+jtransition.arr[tObectId]['gCurrentTransitionSection']+"']").fadeTo(0, 1.0);
			
			
			// make transition
			$("[id='imgTransition']" && "[transitionselection='"+old_selection+"']").fadeTo('slow', 0.0, function() { 
				// Animation complete.
			  	
			  	$("[id='imgTransition']" && "[transitionselection='"+old_selection+"']").hide(); // keeps it from hijacking clicks
				// give it a low stacking order
				$("[id='imgTransition']" && "[transitionselection='"+old_selection+"']").css('zIndex', 1);
		
				//$(this).remove();

				// finalize the new selection by setting it highest in the stack order
				$("[id='imgTransition']" && "[transitionselection='"+jtransition.arr[tObectId]['gCurrentTransitionSection']+"']").css('zIndex', 120);
			});
			
		};
		
});

