	var currentTitle;


$(document).ready(function()
			   {
				   var urlArr = document.location.toString().split("#");
				   if(urlArr.length>1 && urlArr[1] != "anchorTop")
				   {
					   showSection(urlArr[1]);
				   }
				   
				   $('.backToTop').click(function(event){
												  event.preventDefault();
												  		$('body').scrollTo(0,1000);
											  		
												  })
				   
				 
 				$("#container img").load(function(){
											$(this).hide();
											$(this).fadeIn('slow');
										 });
							   $("#siteMenu a").click(
								function(ev)
								{
									 ev.preventDefault();
									 var currentURL = $(this).context.toString();
									 var pathArr = currentURL.split("/");
									 var fileName = pathArr[pathArr.length-1];
									showSection(fileName);
									return false;
								}
								   );
				   $("#siteMenu a img").click(function()
											 {
												
												$("#siteMenu a img").each(
																		  function(index)
																		  {
																			   	this.clicked = false;
																				if(this.src.indexOf("over") > -1)
																				{
																					this.src = this.src.replace("over", "out");
																				}
																		  })
												this.clicked = true;
												this.src = this.src.replace("out","over");
											 });
				   $("#siteMenu a img").mouseover(function()
											 {
												 this.oriSrc = this.src;
											 	this.src = this.src.replace("out","over");
											 });
				   $("#siteMenu a img").mouseout(function()
											 {
												if(this.clicked) return
											 	this.src = this.oriSrc;
											 });
				   $('#contact a').mouseover(function(){
														 $('#titleContainer').text('100 Bank Street_apt 6B_New York NY 10014_T: 212 255 6163_E: crossley.greg@gmail.com');
													 });
				   $('#contact a').mouseout(function(){
													 	if(currentTitle.indexOf("Greg Crossley") != -1)
														{
															currentTitle = '';
														}
														$('#titleContainer').text(currentTitle);
													 });
				   $('#contact a').click(function(){
												  		document.location.href = 'mailto:crossley.greg@gmail.com';
													 });
			   
				   var theMenuImgs = $("#siteMenu a img");
					
				   
				  
				});


	function showSection(fileName)
	{
		document.location.href = document.location.toString().split("#")[0] + "#" + fileName;
		$('#loadedPageContainer').load(fileName, function(responseText, textStatus, XMLHttpRequest)
														  {
															  	var pattern = /<title>(.*?)<\/title>/;
																var matches = responseText.match(pattern);
																var the_string = "";
																try
																{
																	the_string = matches[1];
																	$('#titleContainer').text(the_string);
																	currentTitle = the_string;
																}
																catch(err)
																{
																	
																}
																//detect scoll and hide label
																//$('#loadedPageContainer img').css('opacity','0')
																$('#loadedPageContainer img').load(function(){
																											$(this).animate({opacity:1},1000);
																											});
															
																$('.videoHolder').each(function(){
																									createVideoPlayer(this);
																								});
																//alert($(window).height())
																//alert($(document).height())
																//if($(document).height());
																
																
															});
		$('#siteMenu a img').one('load',function(){
												//$(this).fadeIn('slow');
											});
		
		
		//$("#siteMenu a img").clicked = false;
		//$("#siteMenu a img").src = $("#siteMenu a img").oriSrc;
	}
	var holderCounter = 0;
	function createVideoPlayer(target)
	{
		var pushRight = $(target).hasClass('yr');
		var id = "videoHolder_" + (++holderCounter);
		var src = target.alt;
		var imgSrc = target.src;
		var div = '<div id="'+id+'" class="videoHolderDIV"><img src="'+imgSrc+'" id="'+id+'_img" /><div class="videoPlayer" id="'+id+'_video"></div>';
		var newElement = $(target).replaceWith(div);
		//alert(src)
		var swfVersionStr = "10";
		<!-- To use express install, set to playerProductInstall.swf, otherwise the empty string. -->
		var xiSwfUrlStr = "expressInstall.swf";
		var flashvars = {};
		flashvars.videoSource = src;
		flashvars.container = id;
		var params = {};
		params.quality = "high";
		params.bgcolor = "#000000";
		params.wmode = "transparent";
		params.allowscriptaccess = "sameDomain";
		params.allowfullscreen = "true";
		var attributes = {};
		//attributes.id = "${application}";
		attributes.name = "videoPlayer_" + id;
		attributes.align = "middle";
		swfobject.embedSWF(
			"gregCrossleyVideoPlayer.swf", id+"_video", 
			"282", "232", 
			swfVersionStr, xiSwfUrlStr, 
			flashvars, params, attributes);
		if(pushRight)
		{
			$("#"+id+"_video").css('right','60px');
		}
	}
	
	function darken (id)
	{
		$("#"+id+"_img").animate({opacity:.3}, 600);
	}
	
	function lighten(id)
	{
		$("#"+id+"_img").animate({opacity:1}, 1000)
	}

