$(document).ready(function(){ 

//====== ON LOAD, TAKE URL AND TRANSFORM IT INTO AJAX FRIENDLY URL

		// alert('onready');

		var this_url = document.URL;

		/// if url has a ? in it...
		check = this_url.indexOf("?");
		if(check >= 0){
			
			// alert('url has ? in it', check);
		
			this_url = this_url.replace("http://tosproductions.com","");
			this_url = this_url.replace("http://www.tosproductions.com","");
			this_url = this_url.replace("?video=","");
			this_url = this_url.replace("index.php","");
			this_url = "#/videos"+this_url;
			location.href="http://tosproductions.com/"+this_url;
			
			// alert('location.hrefed');
			
		}
		
   
//===== USE HISTORY ========================================================= //
	
	jQuery.History.bind(function(state){
	
		// alert('.history');
	
		/// get url to load
		var link = state.replace("videos/","");
		link = "inc.video.php?video="+link;
		
		
		$udpate_div = $("#content");
		$loading_div = $("#loading_msg");
		
		$udpate_div.fadeOut('fast', function(){
			//$loading_div.fadeIn('fast');
			//$.scrollTo("#nav");
			
			$udpate_div.load(link, function(){
				//$loading_div.fadeOut('fast');
				$udpate_div.fadeIn();
			});
		});
				
	});        
         
/*

	AJAX UPDATE CONTENT.  SEO-FRIENDLY TOO.
	BY VEDANTA SCRIPTS, FROM SCHRAMDESIGN
	SchramDesign.com | Contact Designer/Developer Jeff Schram at email@schramdesign.com 

	### THIS SCRIPT RELIES ON HAVING HISTORY.JS INSTALLED AND CALLED BY PARENT SCRIPT

*/
       
    $("#video_thumbs a").click(function(){
    
    	// alert('href* clicked');
      
  		$("ul#video_thumbs li a").removeClass("on").addClass("off");
  		$(this).removeClass("off").addClass("on");
 
 	 
		/// set hash
		$this_href = $(this).attr("href");
		
		var hash_link = $this_href.replace("http://tosproductions.com/index.php?video=","");
		var hash_link = $this_href.replace("http://www.tosproductions.com/index.php?video=","");
		
		hash_link = "#/videos/"+hash_link;
		
		location.hash = hash_link;
			    	    	
    	return false;
    });/// end click
    
});    

