$(document).ready(function(){ 
     $("#footer_nav li:first").addClass("first");
     $('#handle').click(function(e){
       $('#item-wrap').slideToggle("medium");
       e.preventDefault();
     });

     $("#get_connected ul").each(function(){$(this).find("li:first").addClass("first");});
 	 $("#resources_nav li:last").addClass("last").find("a").wrapInner("<strong></strong>");

	 function mycarousel_initCallback(carousel){
	    // Disable autoscrolling if the user clicks the prev or next button.
	    $(".next").bind('click', function() {
			carousel.next();
	        carousel.startAuto(0);
	    });

	   $(".prev").bind('click', function() {
			carousel.prev();
	        carousel.startAuto(0);
	    });
         //window.console.log(carousel);
         
	    // Pause autoscrolling if the user moves with the cursor over the clip.
	    $("#video_list_wrap").hover(function(){
	        carousel.stopAuto();
	    }, function() {
	        carousel.startAuto();
	    });
	};


    $('#video_list').jcarousel({
        auto: 7,
        wrap: 'circular',
  		scroll:3,
		animation:1000,
		easing:"swing",
        initCallback: mycarousel_initCallback
    });

	$("#video_list li").each(function(){
		  $this = $(this);
		  $this.data({video: $this.attr("id"), image:$this.find("img").attr("src"), title:$this.find(".title").text()});
	}).hover(
		function(){
			$(this).find(".title").animate({opacity:.5},200);
		},function(){
			$(this).find(".title").animate({opacity:1},200); 
	}); 
	
	function loadVideo(img,vid){
		//window.console.log(vid);
	   // window.console.log(data.('image'));
	    //window.console.log(img + " | " + vid)
		var objHttpFileDataRequest,
			postData;
			
	    postData = "name=&video="+vid+"&image="+img;
		
		//window.console.log(postData);
		if(objHttpFileDataRequest){
			objHttpFileDataRequest.abort();
		} 
	
		objHttpFileDataRequest = $.ajax({
			cache:false,
            data:postData,
			dataType:"html", 
            url: "/includes/html5video.php",
            timeout: 1000,
            type:"GET",
            async:false, 
            error: function(){ 
				
            },
            success: function(e){
			   $("#flash").html(e);       
            }
        });

		objHttpFileDataRequest = null;  
	}  

	   
	$("#video_list li").live('click',function(e){
		$this = $(this);   
		//var video = "<video id='vid' poster='"+$this.data('image')+"' src='"+$this.data('video')+"' width='512' height='305' />";
		//$("#hero").find("#flash").html(video);
		//$("#vid").mediaelementplayer();
		loadVideo($this.data('image'),$this.data('video'));
	});
	
    var firstVid = $("#video_list li:eq(0)");
	loadVideo(firstVid.data('image'),firstVid.data('video'));
	//var video =  "<video id='vid' poster='"+firstVid.data('image')+"' src='"+firstVid.data('video')+"' width='512' height='305' />";
	//$("#hero").find("#flash").html(video);
	//$("#vid").mediaelementplayer();
	
});
