/* 
 * functions common to all trading platforms, both pro and fast
 */
var HomeAll =  {
	container: null,
	demoDialog: null,
	
	init: function(){
	    	
		HomeAll.container = $('div.container');
		/*demo and open account only for logged out user*/
		if(! AppData.isLoggedIn) HomeAll.container.find('a.watchDemoBtn').click(HomeAll.playDemo);
		if(! AppData.isLoggedIn) HomeAll.container.find('a.openAccountBtn').click(openAccount.init);
		
		// not implemented from 11-07-2010 -> setTimeout("HomeAll.newUserVideoInto()",5000);
		
		//get url params for autoplay demo
		if(window.location.href.indexOf('autoPlayDemo=true') > 10){
			HomeAll.playDemo();
		}
	},
	/*
	 * play demo in dialog window
	 */
	playDemo: function(){
		var width = 898;
		var height = 795;
		HomeAll.demoDialog =  $('<div>').attr('id','demoDialog')
		.html('<object width="'+width+'" height="'+height+'">' 
	    	+ '<param name="movie" value="appProxy/bbinary_demo.swf">'
	    	+ '<param name="wmode" value="opaque">'
		    + '<embed src="appProxy/bbinary_demo.swf" width="'+width+'" height="'+height+'" wmode="opaque">'
		    + '</embed>	</object>');
		
		HomeAll.container.append(HomeAll.demoDialog);
		
		
		/* ANOTHER OPTION var flashvars = false;
		var attributes = {};
		attributes.align = "middle";
		var params = {
			  wmode: "transparent"
		}
		swfobject.embedSWF("appProxy/bbinary_demo.swf", "demoVideoPlaceHolder", "750", "663", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
		*/
		HomeAll.container.find('div#demoDialog').dialog({
			autoOpen: true,
			dialogClass: 'bbinary_dialog' ,
			width: width+10,
			height: height+30,
			modal:true,
			title: 'Banc De Binary Demo',
			closeOnEscape: true,
			close: function(){ //cleanup
				$(this).dialog('destroy'); 
				$('#demoDialog').remove()}
			}
		);
	},
	/*
	 * this is triggered when flash video ends
	 */
	demoVideoFinished: function(){
		if(HomeAll.demoDialog)
			HomeAll.demoDialog.dialog('destroy');
		$('#demoDialog').remove();
	},
	
	/************
	 * check if new user, play intro video. mark cookie to not play again
	 * 
	 */
	newUserVideoInto: function(){
		var play = false;
		var lastPlayed = General.getCookie('videoIntroPlayed');
		if(lastPlayed == '')
			play = true;
		if(play) HomeAll.playVideoInto();
	},
	
	playVideoInto: function(){
		HomeAll.container.append(
							$('<div>').attr('id','introVideoContainer')
									.attr('style','height: 360px; width:180px;')
								    .html('<div id="introVideo"></div>')
							);
	
		
		var flashvars = false;
		var attributes = {};
		attributes.align = "middle";
		var params = {
			  wmode: "transparent"
		}
		swfobject.embedSWF("appProxy/introVideo.swf", "introVideo", "360", "360", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
		
		//log cookie that user has seen video
		var date = new Date();
		date.setTime(date.getTime()+(6*30*24*60*60*1000));//six months
		document.cookie="videoIntroPlayed=true; expires="+date.toGMTString();
		$('div#videoIntroContainer').remove();
		//remove div after
		setTimeout('HomeAll.intoVideo_cleanup()',80000);
		
		
	},
	intoVideo_cleanup: function(){
		swfobject.removeSWF("introVideo");
		HomeAll.container.find('div#introVideoContainer').remove();
	}
}

$(document).ready(function() { 
	
	HomeAll.init();
});
