// JavaScript Document

jQuery(document).ready(function() {
   
   
   //alert("ready");
   
	//	Round appropriately id'ed divs
	//jQuery('div[id|=rounded]').corner();
	
	$('a[id^=cat]').click(function() 
					{ 
						
						//alert("clicked nav item");
						
						// turn off all blues...
						$('a[id^=cat]').attr('class', 'nav');
						
						// turn on this blue
						$(this).attr('class', 'nav_on');
						
						
						/*$('a').each(function(e, trg) {
		    
			    	
					    	if ( $(this).text() != "" &&  $(this).text() != "/")
					    	{
					    	
					    		//alert(hiliteMain + " " + hiliteSub + " " + $(this).text().toLowerCase());
					    		if (parentTitle.toLowerCase() == $(this).text().toLowerCase()) $(this).attr('class', 'nav_on');
					    		else $(this).attr('class', 'nav');
					    	
					    	}
				    
					    });*/
						
						
						var id 					= $(this).attr('id');
						var parentCategoryID 	= id.split("_")[1];
						var parentTitle 		= id.split("_")[2]; // .toUpperCase();
								
						$.ajax({
						type: "GET",
						url: "getsubnav.php",
						data: "parentCategoryID="+parentCategoryID+"&parentTitle="+parentTitle,
						success: function(data){
						 
						 	//alert("data" + data);
						 	
						 	$("#subnav").css({'display':'block', 'height':'0px'});
						 	
							 	$("#subnav").html(data);
							 	
							 	$('#subnav').animate({
							    opacity: 1,
							    height: '22px'
							  }, 1000, function() {
							    // Animation complete.
							  });
						 	
						}
						});
							
						
												
					});
					
	//$("#nav").css({'display':'block', 'height':'0px'});
						 	

	
	$('#logo').animate({
	    top: '30px'
	  }, 500, function() {
	    // Animation complete.
	    
	    $('#nav').animate({
			height: '22px'
		  }, 1000, function() {
		    // Animation complete.
		})
	    
	});

	
	resizeToWidth();
	$(window).resize(function() {resizeToWidth()});


});


function resizeToWidth () 
{

	var stripLeft 		= Number($('#projectContentStrip').scrollLeft());
	//alert('stripLeft ' + stripLeft);

	//$('#body_bg').css({'background-size':'cover'}); // 100%;', 'width':'100%', 'height':'100%'});
	
	$('#content').width($(document).width() + 'px'); //  - ($('#div1').height() + $('#div2').height())
	$('#content').height($(document).width() - 140 + 'px'); //  - ($('#div1').height() + $('#div2').height())
	
	$('#content_bg').width($(document).width() + 'px'); //  - ($('#div1').height() + $('#div2').height())
	$('#content_bg').height($(document).width() - 140 + 'px'); //  - ($('#div1').height() + $('#div2').height())
	  
	$('div[id^=projectContent]').width($(document).width() - 240 + 'px'); //  - ($('#div1').height() + $('#div2').height())
	
	$('#scrollingHotSpotRight').css('left', ($(document).width() - 140) + 'px'); //  - ($('#div1').height() + $('#div2').height())
	
	$('#body_bg_home').width($(document).width() + 'px'); //  - ($('#div1').height() + $('#div2').height())
	$('#body_bg_home').height($(document).height() - 140 + 'px'); //  - ($('#div1').height() + $('#div2').height())
	
	$('#body_bg').width($(document).width() + 'px'); //  - ($('#div1').height() + $('#div2').height())
	$('#body_bg').height($(document).height() - 140 + 'px'); //
	
	$('#projectContentStrip').scrollLeft(stripLeft);
}


/*
function getProjects( subCategoryID ) 
{

	//alert("get projects " + subCategoryID);
	
	// turn off all blues (for subnav)...
	$('a[id^=subcat]').attr('class', 'nav');
	
	// turn on this blue
	$('a[id^=subcat_'+subCategoryID+']').attr('class', 'nav_on');
							
	$.ajax({
	type: "GET",
	url: "getprojects.php",
	data: "subCategoryID="+subCategoryID,
	success: function(data){
	 
	 	//alert("got projects " + data);
	 
	 	$("#projects").html(data);
	 	
	}
	});

}
*/

function scrollHorizontallyTo ( projectID )
{
	
	//alert("should scroll to " + '#'+projectID);
	
	$('a[id^=project]').attr('class', 'nav');
	
	// turn on this blue
	$('a[id=project_'+projectID+']').attr('class', 'nav_on');
	
	
	
	//var listItem = $('#' + projectID);
	//var itemIndex = $('#' + projectID).index(); // $('div.scrollableArea:a').index(listItem);
	//alert('Index: ' + itemIndex);
	//$("#makeMeScrollable").smoothDivScroll("moveToElement", "number", itemIndex+1);
	
	//nextScroll();
	
	// Div Scroll
	//var $divScroll = $("#projectContentStrip");
	
	//var linkIndex = $('#' + projectID).index();
	//alert("linkIndex " + linkIndex);
	//var toElement = $("#projectContentStrip").get(linkIndex);
	//alert("toElement " + toElement);
	
	//alert($('#' + projectID).index() + " index" + $("#projectContentStrip").index();
	
	//$divScroll.scrollTo( toElement, 0, {axis:'x', easing:'swing'} ); // '#' + projectID
	
	// Window scroll
	//$.scrollTo( '#' + projectID, 500, {axis:'x', easing:'swing'} );

}

function fadeImageIn(id, delay)
{

	var fadeTime = 0;
	var divImage = '#content_' + id;
	
	setTimeout(function(){
	$(divImage).animate({
		opacity: 1
	  }, fadeTime, function() {
	    // Animation complete.
	})
	}, delay);
	
	//$(divImage).fadeIn(fadeTime);

}

function goHome()
{

	$('a[id^=cat]').attr('class', 'nav');
	window.location.href = "#/";

}


// CHECK SWF ADDRESS FOR THIS FUNCTION NOW
function getFlashMovie(movieName) 
{   
	var isIE = navigator.appName.indexOf("Microsoft") != -1;   
	return (isIE) ? window[movieName] : document[movieName];
	
} 

function resetWhatWeDo()
{

	var movie = getFlashMovie('whatwedo');
	movie.resetFlash();

}

function flashCall()
{
	
	$('#subcat_5_What-we-do').bind('click', function(){resetWhatWeDo();});

}

function addFlashContent()
{

	var flashvars = {
	};
		
	var params = {
		 menu: "false",
		 wmode: "transparent",
		 salign: "t"
	};
		
	var attributes = {
		id: "whatwedo"
	};

	swfobject.embedSWF("datasource/swf/preloader.swf", "flashContainer", "1024", "800", "9", "scripts/expressInstall.swf", flashvars, params, attributes);


}

