jQuery(document).ready(function(){
	var flashvars = {	file: "../video/lamb-1.flv", 
						allowscriptaccess: 'always', 
						allowfullscreen: 'true' ,
						stretching: 'fill', 
						autostart: 'false', 
						repeat: 'never'}
						
	var params = {}
	swfobject.embedSWF("/flash/player-viral.swf", "player", "627", "352", "9.0.0", null, flashvars, params);

	jQuery("#slider").easySlider({
		auto: false,
		continuous: true
	}); 
	jQuery('#recipelink').hide();
});

function playerReady(playerobject) {

	// document.getElementById('player').addViewListener("PLAY", "playaction");
	if (jQuery("#videotitle").html() == '') {
		if (jQuery("div.video_info:first").attr('id').search(/youtube/) == -1 ) {
			vidFile = "/video/" + jQuery("div.video_info:first").attr('id')  + ".flv";
		} else {
			vidFile = jQuery("div.video_info:first").attr('id');
		}
		document.getElementById('player').sendEvent("LOAD", vidFile);
		jQuery(".description_share p:first").html(jQuery("div.video_info:first").find('.videodescription').html());
		jQuery("#videotitle").html(jQuery("div.video_info").find('.videotitle').html());
		jQuery("#videodownloadlink").attr('href', "/video/" + jQuery("div.video_info:first").attr('id') + ".mp4");
		
		jQuery('#recipelink a').attr('href',"/recipe/view/id/" + jQuery("div.video_info:first").attr('rel'));
		
		if (jQuery('.farmingobsession').length == 0){
			vidpage = "petergordon";
		} else {
			vidpage = "obsession"; 
		}
		videotitle = jQuery("div.video_info:first").find('.videotitle').html();
		
		jQuery('.facebook').attr('href', "http://www.facebook.com/sharer.php?u=" 
					+ "http://www.national-obsession.com/main/" + vidpage + "/id/" 
					+ jQuery(".video_info:first").find('.videolink').attr('rel') + "&t=" + videotitle);
		jQuery('.delicious').attr('href', "http://del.icio.us/post?url=" 
					+ "http://www.national-obsession.com/main/" + vidpage + "/id/" 
					+ jQuery(".video_info:first").find('.videolink').attr('rel') + "&t=" + videotitle);
		jQuery('.stumbleupon').attr('href', "http://www.stumbleupon.com/submit?url=" 
					+ "http://www.national-obsession.com/main/" + vidpage + "/id/" 
					+ jQuery(".video_info:first").find('.videolink').attr('rel') + "&title=" + videotitle);
	} else {
		
		if (jQuery("#videodownloadlink").attr('href').search(/youtube/) == -1 ) {
			vidFile = (jQuery("#videodownloadlink").attr('href').substr(0,jQuery("#videodownloadlink").attr('href').length - 3) + "flv");
			
		} else {
			vidFile = jQuery("#videodownloadlink").attr('href').substr(0,jQuery("#videodownloadlink").attr('href').length - 4).replace(/\/video\//, '');
			
		}
		document.getElementById('player').sendEvent("LOAD", vidFile);
	}

	jQuery('#recipelink').show();

	jQuery("div#slider div.video_info a").click(function(ev){

		jQuery("#videodownloadlink").attr('href',"/video/" + jQuery(ev.target).parents("div.video_info").attr('id')  + ".mp4");
		if (jQuery(ev.target).parents("div.video_info").attr('id').search(/youtube/) == -1 ) {
			vidFile = "/video/" + jQuery(ev.target).parents("div.video_info").attr('id')  + ".flv";
			
		} else {
			vidFile = jQuery(ev.target).parents("div.video_info").attr('id');
		}

		document.getElementById('player').sendEvent("LOAD", vidFile);
		jQuery(".description_share p:first").html(jQuery(ev.target).parents("div.video_info").find('.videodescription').html());
		jQuery("#videotitle").html(jQuery(ev.target).parents("div.video_info").find('.videotitle').html());
		
		jQuery('#recipelink a').attr('href',"/recipe/view/id/" + jQuery(ev.target).parents("div.video_info").attr('rel'));
		videotitle = jQuery(ev.target).parents("div.video_info").find('.videotitle').html();


		// and the social media links... 
		if (jQuery('.farmingobsession').length == 0){
			vidpage = "petergordon";
		} else {
			vidpage = "obsession"; 
		}
		jQuery('.facebook').attr('href', "http://www.facebook.com/sharer.php?u=" 
					+ "http://www.national-obsession.com/main/" + vidpage + "/id/" 
					+ jQuery(ev.target).parents().find("a").attr('rel') + "&t=" + videotitle);
		jQuery('.delicious').attr('href', "http://del.icio.us/post?url=" 
					+ "http://www.national-obsession.com/main/" + vidpage + "/id/" 
					+ jQuery(ev.target).parents().find("a").attr('rel') + "&t=" + videotitle);
		jQuery('.stumbleupon').attr('href', "http://www.stumbleupon.com/submit?url=" 
					+ "http://www.national-obsession.com/main/" + vidpage + "/id/" 
					+ jQuery(ev.target).parents().find("a").attr('rel') + "&title=" + videotitle);


		jQuery("a[href$=mp4] img, a[href$=m4v] img").click(function(ev){
			
			pageTracker._trackPageview(jQuery(ev.target).parent().attr('href'));
			
		});
		return false;
	});
}

function playaction() {
	
	//alert("vidfile");
	
}






