/*
	chad park vincent
	10.01.2008

	swedish fish js code.
*/


// Open External Links as Blank Targets via Unobtrusive JavaScript
// http://perishablepress.com/press/2007/11/20/open-external-links-as-blank-targets-via-unobtrusive-javascript/


// OPEN EXTERNAL LINK, XHTML STRICT

// urls for the streaming videos.
var vid1URL = "27605/27605/swedish_fish/Survivor2";		
var vid2URL = "27605/27605/swedish_fish/BoyBurger";

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (
			anchor.getAttribute("href") && ( 
			anchor.getAttribute("rel") == "external" || 
			anchor.getAttribute("rel") == "external nofollow" || 
			anchor.getAttribute("rel") == "nofollow external" )
			)
		anchor.target = "_blank";
	}
}
window.onload = function() {
	externalLinks();
}

$(document).ready(function() {
	
	//stretchLeft();

	//image rollovers based on element id
	$("img").each(function() {
		var thisClass = $(this).attr("class");
		if(thisClass == 'swapme' || thisClass == 'selected') {
		$(this).mouseover(function() {
		 	var thisid = $(this).attr("id");
		 	var imgsrc = "/images/"+thisid+"_on.png";
		 	$(this).attr("src",imgsrc);
		 });
		}
	});
    $("img").each(function() {
     	var thisClass2 = $(this).attr("class");
     	if(thisClass2 == 'swapme') {
     		$(this).mouseout(function() {
     			var thisid = $(this).attr("id");
				var imgsrc = "/images/"+thisid+"_off.png";
				$(this).attr("src",imgsrc);
   			});
    	}
    });
    
    // if a vidthumb is clicked, show the appropriate video
    $("#vidthumb1").click(function() {
    	playVideo(this);
		//updateVideoNav(this);
		//showEmbedCode(this);
    });
    $("#vidthumb2").click(function() {
    	playVideo(this);
		//updateVideoNav(this);
		//showEmbedCode(this);
    });
//delishusbeefandporkandchickenandturkeyallattehsameteim!!!!mmm.
	// focus and select the text in the embed code field when clicked.
	$("#embed_code").click(function() {
		selectEmbedCode(this);
	});
	
	$("#print1").click(function() {
		// tracking code
		s.tl(true,'o','PrintAdTeddyPanini');
	});
	$("#print2").click(function() {
		// tracking code
		s.tl(true,'o','PrintAdBoyBurger');
	});
	$("#print3").click(function() {
		// tracking code
		s.tl(true,'o','PrintAdKittySandwich');
	});
	
}); /* end of document.ready */



// autoplay videos when the user clicks a thumb.
function playerReady(obj) {
	var id = obj['id'];
	var player = document.getElementById(id);
	player.sendEvent('PLAY',true);
}

/*	playVideo(domelement e)
	- takes a DOM element (video thumbnail) and resubmit
	all of the flash vars for that particular video.
*/
function playVideo(e) {
	
	// initialize element id,streamer url, and file name.
	var thisid = $(e).attr("id");
	var mystreamer = "";
	var myfile = "";
	mystreamer = 'rtmp://cp27605.edgefcs.net/ondemand';
	
	// which video was clicked?
	if(thisid == 'vidthumb1') {
		myfile = vid1URL;
	}
	else if(thisid == 'vidthumb2') {
		myfile = vid2URL;
	}

	// set the params for the swfobject embed.
	// only flashvars.streamer and flashvars.file
	// are dynamic.
	var swf = "/flash/flv_player/player.swf";
	var replaceElementId = 'flash';
	var width = '600';
	var height = '364';
	var requiredVersion = '9.0.28';
		
	var flashvars = {
		agecheck_passed: '<?php echo $agecheck_value; ?>',
		//file:  'http://www.youtube.com/watch?v=fB0_vJUc3o4',
		skin: '/flash/flv_player/sf.swf',
		type: 'video',
		streamer: mystreamer,
		file:  myfile
	};
		
	var params = {
		menu: 'false', 
		scale: 'noscale',
		wmode: 'transparent',
		allowfullscreen: true,
		allowScriptAccess: 'always'
	};
		
	var attributes = { 
		id: 'flash', 
		name: 'flash', 
		background: '#000000'
	};
		
	if ($.cookie("use_flash") != "n") {
		swfobject.embedSWF(swf, replaceElementId, width, height, requiredVersion, '/js/swfobject/expressInstall.swf', flashvars, params, attributes);
	}
}


// generate and show embed code in the text field.
function showEmbedCode(el) {
	// generate code
	var vidId = $(el).attr("id");
	//alert(vidId+" clicked!");
	if(vidId == 'vidthumb1') {
		$("#embed_code").val(vid1EC);
	} else if(vidId == 'vidthumb2') {
		$("#embed_code").val(vid2EC);
	}
}

// focus and select embed code
function selectEmbedCode(el) {
	// focus the field and select it.
	$(el).focus();
	$(el).select();
}









//--> 



