$(document).ready(function(){
	var imgPath,theID,trimID,thePDFPath,theVideoName;	
	setCookie();
	
	$("#site-container #content-container .four-col-feature .product-details #product-lessons ul li span:last-child").addClass('btn');// all courses
	
	// swap 'download course deatils' text (purple/grey)
	$("#site-container #content-container .four-col-feature .product-details .download-pdf span").mouseover(function(){
		$(this).css({"text-decoration":"underline"});
	}).mouseout(function(){
		$(this).css({"text-decoration":"none"});
	});	
	
	// Benefits padding specifics:
		// 2nd benefit remove padding-right 
		$("#site-container #content-container #three-one-cols #three-cols #mywealth-benefits div:nth-child(2)").css('padding','0px 0px 30px 0px');
		var lastBenefit = $("#site-container #content-container #three-one-cols #three-cols #mywealth-benefits .benefit").size();
		// last one, remove all padding
		$("#site-container #content-container #three-one-cols #three-cols #mywealth-benefits div:nth-child("+ lastBenefit +")").css('padding','0px');
		
		
	// download course pdf click
	$("#site-container #content-container .four-col-feature .product-details .download-pdf").click(function () {
		//alert("connect to download pdf for: " + $(this).parent().attr("id"));
		thePDFPath = "media/pdf/" + this.id + ".pdf";
		//window.location.href = thePDFPath;
		winOptions = {name:"myWealthCoursePdf",urlpath:thePDFPath};
		openNewWin(winOptions);	
	});

	// swap 'enroll now' 
	$("#site-container #content-container .four-col-feature .product-details .product-buy #purchase-btn img").mouseover(function(){
		$(this).attr("src", "http://www.mywealth.com/media/img/ui/btns/btn-enrollnow2-on.png");
	}).mouseout(function(){
		$(this).attr("src", "http://www.mywealth.com/media/img/ui/btns/btn-enrollnow2-off.png");
	});	

	// swap contact btn	
	$("#site-container #content-container #three-one-cols #three-cols #got-questions #contact img").mouseover(function(){
		$(this).attr("src", "http://www.mywealth.com/media/img/ui/btns/btn-contact-on.png");
	}).mouseout(function(){
		$(this).attr("src", "http://www.mywealth.com/media/img/ui/btns/btn-contact-off.png");
	});	

	// swap 'view details' btn (purple)
	$("#site-container #content-container #three-one-cols #productTable table tr#btns img").mouseover(function(){
		thePath = "http://www.mywealth.com/media/img/ui/btns/" + $(this).attr("class") + "-on.png";
		$(this).attr("src", thePath);
	}).mouseout(function(){
		thePath = "http://www.mywealth.com/media/img/ui/btns/" + $(this).attr("class") + "-off.png";
		$(this).attr("src", thePath);
	});	

	// 'enroll now' over
	$("#site-container #content-container .four-col-feature .forum-details .product-buy #purchase-btn img").mouseover(function(){
		$(this).attr("src", "http://www.mywealth.com/media/img/ui/btns/btn-enrollnow2-on.png");
	}).mouseout(function(){
		$(this).attr("src", "http://www.mywealth.com/media/img/ui/btns/btn-enrollnow2-off.png");
	});	

	// course titles over
	$("#site-container #content-container .four-col-feature .product-details #product-lessons ul li span:last-child").mouseover(function(){
		$(this).css({"text-decoration":"underline"});
	}).mouseout(function(){
		$(this).css({"text-decoration":"none"});
	});	
	
	// course titles click 
	// Assumes: click launches video, and parent <li> has id with video name prefix (no '.flv')
	$("#site-container #content-container .four-col-feature .product-details #product-lessons ul li span:last-child").click(function () {
		// UNCOMMENT FOR COURSE VIDEOS
		//theVideoName = $(this).parent().attr("id"); 
		
		// COMMENT OUT WHEN COURSE VIDEOS ARE IN PLACE
		theVideoName = "myWealth-comingsoon"; // UNCOMMENT FOR COURSE VIDEOS
		vidPlayer.sendEvent('STOP'); 
		vidPlayer.sendEvent('LOAD', generateVideoName(theVideoName)); 
		vidPlayer.sendEvent('PLAY'); 
		return false;
	});

	//  enroll click
	$("#site-container #content-container .four-col-feature .product-details .product-buy, #site-container #content-container #three-one-cols #productTable table tr#btns img.btn-enrollnow").click(function () {
		theID = $("#site-container #content-container .four-col-feature .product-details .product-buy").attr("id");
		trimID = theID.substring(theID.indexOf("-")+1,theID.length);
		thePath = "https://www.e-junkie.com/ecom/gb.php?c=cart&i=" + trimID + "&cl=29055&ejc=2"; 
		winOptions = {target:"_blank",name:"mywealthCart",urlpath:thePath};
		openNewWin(winOptions);	
	});

	//  details click
	$("#site-container #content-container #three-one-cols #productTable table tr#btns img").not(".btn-enrollnow").click(function () {
		theID = $(this).parent().attr("id");
		thePath = theID + ".php"; 
		goToURL(thePath);
	});

	//  get flash click
	$(".video-module #video-player #get-flash").click(function () {
		thePath = "http://www.adobe.com/go/getflashplayer";
		winOptions = {target:"_blank",name:"getFlash",urlpath:thePath};
		openNewWin(winOptions);	
	});

	// contact btn click
	$("#site-container #content-container #three-one-cols #three-cols #got-questions #contact").click(function () {
		theID = this.id;
		thePath = theID.substring(theID.indexOf("-")+1,theID.length) + ".php"; // clean up id by removing 'nav_'
		goToURL(thePath);
	});

	// last div in product-details doesn't need padding-bottom
	$("#site-container #content-container .four-col-feature .product-details div:last-child").css("padding","0");

	createPlayer('vidPlayer1', generateVideoName($("#default-video").html())); // checks #default-video <span> for default, if none, myWealth-comingsoon.flv is used
	
});


var vidPlayer = null;
var videoFileName;
var videoPrefix = 'http://www.mywealth.com/media/video/';

function generateVideoName(videoName){
	// assumes videos do not have the suffix ".flv"
	videoFileName = null; // reset
	videoName ? doNothing() : videoName = "myWealth-comingsoon";// if  videoName is null/undefined use coming soon video
	videoFileName = videoPrefix + videoName + ".flv"; // build
	return videoFileName;
}

function playerReady(thePlayer) {
	vidPlayer = document.getElementById(thePlayer.id);
}

function createPlayer(thePlayer, theFile) {
	var flashvars = {
		file:theFile, 
		autostart:"false"
	};

	var params = {
		allowfullscreen:"true", 
		allowscriptaccess:"always"
	};

	var attributes = {
		id:thePlayer,  
		name:thePlayer
	};

	swfobject.embedSWF("http://www.mywealth.com/media/swf/player-licensed.swf", "video-player", "470", "320", "9.0.115", false, flashvars, params, attributes);
}