var player;

function playerReady(obj) {
	player = document.getElementById(obj.id);
}

function hideVideo() {
	$('#videoContainer').hide(); 
	//.hide() will cause IE problem
	//.html() destroy the video and rebuild it
	$('#videoContainer').html('<div id="closeBtn"><img src="' + siteRoot + 'images/closeBtn.png" width="45" height="10"></img></div><div id="videoPlayer"></div>');
	swfobject.embedSWF(siteRoot + "swf/player.swf", "videoPlayer", "478", "289", "9.0.124", false, {file: siteRoot + videoURL, id:'videoPlayer', autostart: 'true', backcolor: '#dfd8cb'}, {allowscriptaccess: 'always', allowfullscreen: 'true'}, {id:'videoPlayer', name:'videoPlayer'});
}

$(document).ready(function() {
	if(videoURL== '')
		{
	swfobject.embedSWF(siteRoot + "swf/ticker-home.swf", "videoPlayer", "533", "141", "9.0.124", false, null, {allowscriptaccess: 'always', allowfullscreen: 'true', wmode: 'transparent'}, {id:'videoPlayer', name:'videoPlayer'});
	setTimeout('simulateClick()', 1500);
		}
	else if(videoURL=='secVisit')
		{
		
		}
	else
		{
	swfobject.embedSWF(siteRoot + "swf/player.swf", "videoPlayer", "478", "289", "9.0.124", false, {file: siteRoot + videoURL, id:'videoPlayer', autostart: 'true', backcolor: '#dfd8cb'}, {allowscriptaccess: 'always', allowfullscreen: 'true'}, {id:'videoPlayer', name:'videoPlayer'});
	$('#showLink').bind('click', showVideo);
		}
	//setTimeout('showVideo()', 1500);
});

function simulateClick()
{
	$('#showLink').click();
//	console.log('here!');
	$('#videoContainer').css('display', 'block');
	bindClose();
	$('#TB_window').bind('unload', function() {
		setTimeout('hideVideo()', 10);
	});
	/*div = get
	clickObj = document.createElement('a');
	clickObj.setAttribute('id','hello');
	clickObj.setAttribute('class','thickbox');
	clickObj.setAttribute('pageTracker._trackEvent("Video", "Play", "Recycling");');
	clickObj.setAttribute('href', '#TB_inline?height=355&width=542&inlineId=videoContainer');
	$(clickObj).click();*/
}

function showVideo()
{
//	console.log('here!');
	$('#videoContainer').css('display', 'block');
	bindClose();
//	bindLink();
	$('#TB_window').bind('unload', function() {
		setTimeout('hideVideo()', 10);
	});
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


