function getFlashMovieObject(movieName){
	    if (window.document[movieName]){
	        return window.document[movieName];
	    }
	    if (navigator.appName.indexOf("Microsoft Internet")==-1){
	        if (document.embeds && document.embeds[movieName])
	            return document.embeds[movieName];
	    }
	    else{
	        return document.getElementById(movieName);
	    }
		
}

function playSound(){
  var flashMovie=getFlashMovieObject("sound_play");
  //flashMovie.sendTextToFlash();
}



function setGalleryPic( current_src, new_src ){
  
  if (jwplayer()){
  	jwplayer().stop();
  }
  $("#blk_pas_project #loading").show();

  $('#gallery_main_image').attr('src', new_src).load(function() {
    $("#blk_pas_project #loading").hide();
  });

}



function playVideo(videofile){
	// By: Adam Jones
	// Created: 7/12/11
	
	videofile=/pa_assets/+videofile;
	//alert("Requested Video: "+videofile);
	
	$('.gallery_image_holder').addClass('off_screen');	
	
	jwplayer('videowrapper').setup({
		'id': 'videoPlayer',
		'autostart': true,
		'width': '702',
		'height': '395',
		'provider': 'video',
		'controlbar': 'over',
		'allowfullscreen': 'true',
		'file': videofile,
		'plugins': {
		   'sharing-3': {}
		},
		'modes': [
			{type: 'flash', src: 'system/application/themes/peteranderson/swf/player.swf', config: {'skin': 'system/application/themes/peteranderson/swf/glow.zip'}} ,
			{type: 'html5', config: {'autostart': false}},
			{type: 'download'}
		]
	  });
	  jwplayer("videowrapper").onError(function() {
		alert("An error occured loading the video player, please let us know about this.");
	  });
	  
}

// event captures ...
$(document).ready(function() {

	$('.nav_3d').hover(function(){
		playSound();
	});
	
	//alert($.client.os);
	//alert($.client.browser);

	if($.client.browser == "Firefox" && $.client.os == "Mac"){
		top = parseInt( $('.title_section h2').css("top") ) - 1;
		$('.title_section h2').css("top" , top + "px" );
	}
	
	if($.client.browser == "Safari" && $.client.os == "Mac"){
		top = parseInt( $('.title_section h2').css("top") ) - 1;
		$('.title_section h2').css("top" , top + "px" );
	}

  

	content_defecit = $(window).height() - $("#wrapper").height();
	if(content_defecit >= 120){
		newContentHeight = $("#content").height() + content_defecit;
		newContentHeight -= 120;
		$("#content").height(newContentHeight);
	}
	
	$('.jq_offset_a').bind("click",function(){
		$(".jq_saved").hide();
		posleft = $('#blk_pas_project h2').position().left;
		
		if( $(this).attr("direction") == 1 ){
			posleft += parseInt( $(this).attr("value") );
		} else {
			posleft -= parseInt( $(this).attr("value") );
		}
		
		$('#title_offset_a').html(posleft);
		$('#blk_pas_project h2').css("left",posleft);
	});
	
	$('.jq_offset_b').bind("click",function(){
		$(".jq_saved").hide();
		posleft = parseInt( $(".proj_desc p").css("text-indent") );
		
		if( $(this).attr("direction") == 1 ){
			posleft += parseInt( $(this).attr("value") );
		} else {
			posleft -= parseInt( $(this).attr("value") );
		}
		
		$('#title_offset_b').html(posleft);
		$(".first_para").css("text-indent",posleft + "px" );
	});


	$('.jq_save_title_offsets').bind("click",function(){
		ofs1 = parseInt( $('#blk_pas_project h2').position().left );
		ofs2 = parseInt( $(".first_para").css("text-indent") );
		ofs = ofs1 + "," + ofs2;
		$('#ajax').load( SUB_FOLDER + "system/application/themes/peteranderson/ajax/ajax_update_settings.php" , { "projectID" : pageID, "titleOffsets" : ofs1 + "," + ofs2  } , function(){
		  
		});
		$(".jq_saved").show();
	});



  	// gallery back button
  	$('.jq_gallery_back').bind("click",function(){										  
	if($('#gallerynav .over').next().hasClass("jq_gallery_nav_index")){
	  $('#gallerynav .over').next().trigger("click");
	}
	return false;
  	});

	// gallery forward button
 	$('.jq_gallery_forward').bind("click",function(){
		if($('#gallerynav .over').prev().hasClass("jq_gallery_nav_index")){
			$('#gallerynav .over').prev().trigger("click");
		}
		return false;
  	});

    
	
  	// gallery index link clicked
 	 $('.jq_gallery_nav_index').bind("click",function(){
	
		$(".asset_extra").hide();
		
		if( $( ".jq_asset_test_" + $(this).attr("index") ).length != 0 ){
			$( ".jq_asset_test_" + $(this).attr("index") ).fadeIn();
			$("#default_text").hide();
		} else {
			$("#default_text").show();
		}
		
		//$('.jq_gallery_forward').attr("onclick","flv_player.changeText('title-virgin_queen/virginqueen_forPASwebsite2.flv');");
		
		$('.jq_gallery_nav_index').removeClass("over");
		$(this).addClass("over");
		
		
		// CHANGE CONTENT...
		if( $(this).hasClass('jq_vid_file') ){
			playVideo($(this).attr("href"));
		} else {
		  setGalleryPic( $('#gallery_main_image').attr("src") , $(this).attr('href') );
		  $('.gallery_image_holder').removeClass('off_screen');
		}
	
		return false;
  	});

	
    $('#header').css("z-index", "100" );
	
    $('.scroll_pane').jScrollPane();

	$('.jq_has_sub').hover(
		function(){
		  $('.jq_sub_2',this).show();
		}
		,
		function(){
		  $('.jq_sub_2',this).hide();
		}
	);

	$('#blk_pas_navigation a').hover(
		function(){
		playSound();
	});

	$('#blk_pas_navigation a').hover(
		function(){
		  playSound();
		}
	);


	$('.jq_project').hover(
		function(){
		  playSound();
		  $('.jq_project_sub_heading',this).fadeIn("fast");
		  $('span',this).addClass("display_text");
		  $('.shadow_top',this).addClass("pic_hover");
		}
		,
		function(){
		  $('.jq_project_sub_heading',this).fadeOut("fast");
		  $('span',this).removeClass("display_text");
		  $('.shadow_top',this).removeClass("pic_hover");		  
		}
	);

	$('.jqueryslidemenu ul li ul li').hover(
		function(){
		  $(this).addClass("position_right");
		}
		,
		function(){
		  $(this).removeClass("position_right");
		}
	);

	$('#blk_pas_navigation').hover(
		function(){
		  $(this).addClass("nav_top");
		  $("#blk_pas_news_summary").addClass("elem_bottom");
		}
	);

	$('.jq_contact_form_name').bind("click", function(){
	  if( $(this).attr("value") == "Your name" ){
		$(this).attr("value" , "" );
	  };	
	});

	$('.jq_contact_form_company').bind("click", function(){
	  if( $(this).attr("value") == "Your company" ){
		$(this).attr("value" , "" );
	  };	
	});

	$('.jq_contact_form_email').bind("click", function(){
	  if( $(this).attr("value") == "Your mail address" ){
		$(this).attr("value" , "" );
	  };	
	});

	$('.jq_contact_form_message').bind("click", function(){
	  if( $(this).attr("value") == "Inquiry" ){
		$(this).attr("value" , "" );
	  };	
	});

});

