var d = new Date();
document.cookie = "timezone_offset=" + escape( d.getTimezoneOffset() * 60 );


var ajax_path = www_root + 'ajax/?jsoncallback=?';


// Globals for Flash Player
// Major version of Flash required
var requiredMajorVersion = 9;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 28;
				


	// this function is called when an ajax request error happens
	function ajax_error( XMLHttpRequest, url ) {
//		alert( 'Url : ' + url + "\nServer response :\n" + XMLHttpRequest.responseText );
//		$('body').append('Url : ' + url + "\nServer response :\n" + XMLHttpRequest.responseText);
	}
	
	// display an error text
	function display_error( txt ) {
		alert( txt );
	}
	
	
	$(document).ready(function(){
		addReflections();
		
		// assign the ajax error event to the document. it can also be assigned to a div and write into the div
		$(document).ajaxError(function(event, request, settings){
		   ajax_error( request , settings.url );
		 });
	
		// start lightbox
		$('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel

		// <a> form button
		$('a[rel^=afrmsub]').click(function(){
			tmp = $(this).attr('rel');
			tmp = tmp.substring(9); // get the form id
			$( '#' + tmp ).submit();
			return false;
		}); 
		
		// front page ad
		var ad_index = 0;
		$('#ad_r').click(function(){
			ad_index = ad_index + 1;
			if ( !a_ad[ad_index] ) ad_index = 0;
			$('#ad_href').attr('href', a_ad[ad_index]['href'] );
			$('#ad_image').attr('src', a_ad[ad_index]['src'] );
			return false;
		});
		$('#ad_l').click(function(){
			ad_index = ad_index - 1;
			if ( !a_ad[ad_index] ) ad_index = a_ad.length - 1;
			$('#ad_href').attr('href', a_ad[ad_index]['href'] );
			$('#ad_image').attr('src', a_ad[ad_index]['src'] );
			return false;
		});
		// display the first ad
		if ( typeof a_ad != 'undefined' )
		if ( a_ad[0]){
			$('#ad_href').attr('href', a_ad[0]['href'] );
			$('#ad_image').attr('src', a_ad[0]['src'] );
		}
	});
	
	function no_history_server_post( data , callback) {
		$.getJSON( ajax_path , data , callback );
	}
	
	var check_url = false;
	var post_data = '';
	var _old_url = '';
	var _click_made = false;
	var _urls = []; // _urls[i] = 'www.ulr.com';
	var _datas = []; // _datas[id_ud'] = { m : 'asdad' };
	
	
	// function used to post an ajax call to the server.
	// data is an array with the data passed to the server and 'callback' is the name of the callback function function
	// ex : server_post( { m : 'my_module' , n : 5 } , display_vode );
	function server_post( data , callback) {
		$.getJSON( ajax_path , data , callback );
		post_data = data;
		if ( !check_url ) {
			_old_url = document.location.href;
			insert_data( _old_url, data);
			setInterval( ch_url, 500 );
			check_url = true;
		}
	}
	
	// HOW AJAX "PSEUDO - HISTORY" WORKS
	//
	// any ajax call provide also an object called "data".
	// any click on a page <a> tag that should change the page by a ajax call, sets the boolean variable _click_made to true.
	// the js checks at every 300ms with fucntion "ch_url" to see if the page urls has changed. 
	// if the page url has changed by a click on a <a> tag then we save the "data" object coresponding to that url.
	// of the page url has changed but not a user changed it (_click_made == false) them the user pressed the back or forward button
	// we load the data object coresponding to the url and call 2 functions :
	// 1. before_server_call() is a function that removes the old page information from browser display
	// 2. server_post(data_url, server_callback). server_post makes the ajax call and after the server returns data it calls the function "server_callback";
	//
	// TODO ... when building with this :
	// make sure any link, select change, user action that does an ajax call , sets the _click_made = true !
	// make sure u have this 2 functions : before_server_call() and server_callback();
	function ch_url()
	{
		_new_url = document.location.href;
		if ( _new_url != _old_url ) {
			_old_url = _new_url;
			
			if ( _click_made ) {
				insert_data( _old_url, post_data);
				_click_made = false;
			}else {
				tmp = get_data( _new_url );
				before_server_call();
				server_post( tmp , server_callback );
			}
		}
	}
	
	function get_data( url ) {
		return _datas[ get_url_id(url) ];
	}
	
	function insert_data( _old_url, data ) {
		id_url = insert_url( _old_url );
		_datas[ id_url ] = data;
	}
	
	function insert_url( url ) {
		id_url = get_url_id(url);
		if ( id_url == false ) {
			_urls.push(url);
			return get_url_id( url );
		}else
			return id_url;
	}
	
	function get_url_id( url ) {
		ret = false;
		for ( i = 0 ; i < _urls.length ; i ++) 
			if ( _urls[i] == url ) {
				ret = i;
				break;
			}
		return ret;
	}
	
	
	
	// retun the code
	function loader() {
//		return '<img id="loader" src="' + www_root + 'public/images/ajax-loader.gif" />';
		return '<div class="loader"><object width="120" height="50"><param name="movie" value="' + www_root + 'public/flash/loader.swf"></param><param name="wmode" value="transparent"></param><embed src="' + www_root + 'public/flash/loader.swf" wmode="transparent" type="application/x-shockwave-flash" width="120" height="50"></embed></object></div>';
	}
	
	function clearer( height ) {
		if ( !height ) height = 1;
		return '<div class="clearBoth" style="height:' + height + 'px"></div>';
	}
	
	function parse_location() {
		// this function was created for the pagination to work also with :
		// www_roo/live#page/2/category/5
		// what it does. e.g. : var page = 2; var category = 5;
		 s = document.location.hash.substr(1).split('/');
		 if ( s ){
			 for ( i = 0 ; i < s.length ; i += 2 )
				if ( s[i] && s[i+1])
					eval(s[i] + " = '" + s[i+1] + "'");
		 }
	}
	
	function add_to_watchlist(id) {
		server_post( { m : 'add_to_watchlist' , show_id : id } , function( data ) {
				if ( data['err'] ) {
					// display_error can be found in the utils.js ; for start it alerts the error text
					display_error( data['err'] );
				}else {
					$('div[name=add_to_watchlist_' + id + ']').each(function(){  $(this).html('Added!'); });
				}
			});
	}
	
	/** broadcast.js 
	function goToLogin(url) {
		this.href = url;
	}
	//deleteCookie('broadcast');
	**/

	function playBroadcast(id) {
		
		var sw = screen.width, sh = screen.height;
		var height = 609;
		var ulx = ((sw-(721))/2), uly = ((sh-(height))/2);
		
		broadcastWindow = window.open( www_root + 'broadcast/channel/'+id,'Broadcast','width=721,height='+height+',left='+ulx+',top='+uly+',resizable=1');
	}
	//ac_oetags.js
	var isIE=(navigator.appVersion.indexOf("MSIE")!=-1)?true:false;var isWin=(navigator.appVersion.toLowerCase().indexOf("win")!=-1)?true:false;var isOpera=(navigator.userAgent.indexOf("Opera")!=-1)?true:false;function ControlVersion(){var version;var axo;var e;try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");version=axo.GetVariable("$version")}catch(e){}if(!version){try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");version="WIN 6,0,21,0";axo.AllowScriptAccess="always";version=axo.GetVariable("$version")}catch(e){}}if(!version){try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");version=axo.GetVariable("$version")}catch(e){}}if(!version){try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");version="WIN 3,0,18,0"}catch(e){}}if(!version){try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");version="WIN 2,0,0,11"}catch(e){version=-1}}return version}function GetSwfVer(){var flashVer=-1;if(navigator.plugins!=null&&navigator.plugins.length>0){if(navigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave Flash"]){var swVer2=navigator.plugins["Shockwave Flash 2.0"]?" 2.0":"";var flashDescription=navigator.plugins["Shockwave Flash"+swVer2].description;var descArray=flashDescription.split(" ");var tempArrayMajor=descArray[2].split(".");var versionMajor=tempArrayMajor[0];var versionMinor=tempArrayMajor[1];var versionRevision=descArray[3];if(versionRevision==""){versionRevision=descArray[4]}if(versionRevision[0]=="d"){versionRevision=versionRevision.substring(1)}else if(versionRevision[0]=="r"){versionRevision=versionRevision.substring(1);if(versionRevision.indexOf("d")>0){versionRevision=versionRevision.substring(0,versionRevision.indexOf("d"))}}var flashVer=versionMajor+"."+versionMinor+"."+versionRevision}}else if(navigator.userAgent.toLowerCase().indexOf("webtv/2.6")!=-1)flashVer=4;else if(navigator.userAgent.toLowerCase().indexOf("webtv/2.5")!=-1)flashVer=3;else if(navigator.userAgent.toLowerCase().indexOf("webtv")!=-1)flashVer=2;else if(isIE&&isWin&&!isOpera){flashVer=ControlVersion()}return flashVer}function DetectFlashVer(reqMajorVer,reqMinorVer,reqRevision){versionStr=GetSwfVer();if(versionStr==-1){return false}else if(versionStr!=0){if(isIE&&isWin&&!isOpera){tempArray=versionStr.split(" ");tempString=tempArray[1];versionArray=tempString.split(",")}else{versionArray=versionStr.split(".")}var versionMajor=versionArray[0];var versionMinor=versionArray[1];var versionRevision=versionArray[2];if(versionMajor>parseFloat(reqMajorVer)){return true}else if(versionMajor==parseFloat(reqMajorVer)){if(versionMinor>parseFloat(reqMinorVer))return true;else if(versionMinor==parseFloat(reqMinorVer)){if(versionRevision>=parseFloat(reqRevision))return true}}return false}}function AC_AddExtension(src,ext){if(src.indexOf('?')!=-1)return src.replace(/\?/,ext+'?');else return src+ext}function AC_Generateobj(objAttrs,params,embedAttrs){var str='';if(isIE&&isWin&&!isOpera){str+='<object ';for(var i in objAttrs)str+=i+'="'+objAttrs[i]+'" ';str+='>';for(var i in params)str+='<param name="'+i+'" value="'+params[i]+'" /> ';str+='</object>'}else{str+='<embed ';for(var i in embedAttrs)str+=i+'="'+embedAttrs[i]+'" ';str+='> </embed>'}document.write(str)}function AC_FL_RunContent(){var ret=AC_GetArgs(arguments,".swf","movie","clsid:d27cdb6e-ae6d-11cf-96b8-444553540000","application/x-shockwave-flash");AC_Generateobj(ret.objAttrs,ret.params,ret.embedAttrs)}function AC_GetArgs(args,ext,srcParamName,classid,mimeType){var ret=new Object();ret.embedAttrs=new Object();ret.params=new Object();ret.objAttrs=new Object();for(var i=0;i<args.length;i=i+2){var currArg=args[i].toLowerCase();switch(currArg){case"classid":break;case"pluginspage":ret.embedAttrs[args[i]]=args[i+1];break;case"src":case"movie":args[i+1]=AC_AddExtension(args[i+1],ext);ret.embedAttrs["src"]=args[i+1];ret.params[srcParamName]=args[i+1];break;case"onafterupdate":case"onbeforeupdate":case"onblur":case"oncellchange":case"onclick":case"ondblClick":case"ondrag":case"ondragend":case"ondragenter":case"ondragleave":case"ondragover":case"ondrop":case"onfinish":case"onfocus":case"onhelp":case"onmousedown":case"onmouseup":case"onmouseover":case"onmousemove":case"onmouseout":case"onkeypress":case"onkeydown":case"onkeyup":case"onload":case"onlosecapture":case"onpropertychange":case"onreadystatechange":case"onrowsdelete":case"onrowenter":case"onrowexit":case"onrowsinserted":case"onstart":case"onscroll":case"onbeforeeditfocus":case"onactivate":case"onbeforedeactivate":case"ondeactivate":case"type":case"codebase":ret.objAttrs[args[i]]=args[i+1];break;case"id":case"width":case"height":case"align":case"vspace":case"hspace":case"class":case"title":case"accesskey":case"name":case"tabindex":ret.embedAttrs[args[i]]=ret.objAttrs[args[i]]=args[i+1];break;default:ret.embedAttrs[args[i]]=ret.params[args[i]]=args[i+1]}}ret.objAttrs["classid"]=classid;if(mimeType)ret.embedAttrs["type"]=mimeType;return ret}
	
	//reflections
	if(!document.myGetElementsByClassName){document.myGetElementsByClassName=function(className){var children=document.getElementsByTagName('*')||document.all;var elements=new Array();for(var i=0;i<children.length;i++){var child=children[i];var classNames=child.className.split(' ');for(var j=0;j<classNames.length;j++){if(classNames[j]==className){elements.push(child);break;}}}
	return elements;}} var Reflection={defaultHeight:0.5,defaultOpacity:0.5,add:function(image,options){Reflection.remove(image);doptions={"height":Reflection.defaultHeight,"opacity":Reflection.defaultOpacity}
	if(options){for(var i in doptions){if(!options[i]){options[i]=doptions[i];}}}else{options=doptions;} try{var d=document.createElement('div');var p=image;var classes=p.className.split(' ');var newClasses='';for(j=0;j<classes.length;j++){if(classes[j]!="reflect"){if(newClasses){newClasses+=' '} newClasses+=classes[j];}} var reflectionHeight=Math.floor(p.height*options['height']);var divHeight=Math.floor(p.height*(1+options['height']));var reflectionWidth=p.width;if(document.all&&!window.opera){if(p.parentElement.tagName=='A'){var d=document.createElement('a');d.href=p.parentElement.href;}
	d.className=newClasses;p.className='reflected';d.style.cssText=p.style.cssText;p.style.cssText='vertical-align: bottom';var reflection=document.createElement('img');reflection.src=p.src;reflection.style.width=reflectionWidth+'px';reflection.style.display='block';reflection.style.height=p.height+"px";reflection.style.marginLeft="1px";reflection.style.border="0px none";reflection.style.marginBottom="-"+(p.height-reflectionHeight)+'px';reflection.style.filter='flipv progid:DXImageTransform.Microsoft.Alpha(opacity='+(options['opacity']*100)+', style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy='+(options['height']*100)+')';d.style.width=reflectionWidth+'px';d.style.height=divHeight+'px';p.parentNode.replaceChild(d,p);d.appendChild(p);d.appendChild(reflection);}else{var canvas=document.createElement('canvas');if(canvas.getContext){d.className=newClasses;p.className='reflected';d.style.cssText=p.style.cssText;p.style.cssText='vertical-align: bottom';var context=canvas.getContext("2d");canvas.style.height=reflectionHeight+'px';canvas.style.width=reflectionWidth+'px';canvas.height=reflectionHeight;canvas.width=reflectionWidth;canvas.style.marginLeft="1px";d.style.width=reflectionWidth+'px';d.style.height=divHeight+'px';p.parentNode.replaceChild(d,p);d.appendChild(p);d.appendChild(canvas);context.save();context.translate(0,image.height-1);context.scale(1,-1);context.drawImage(image,0,0,reflectionWidth,image.height);context.restore();context.globalCompositeOperation="destination-out";var gradient=context.createLinearGradient(0,0,0,reflectionHeight);gradient.addColorStop(1,"rgba(255, 255, 255, 1.0)");gradient.addColorStop(0,"rgba(255, 255, 255, "+(1-options['opacity'])+")");context.fillStyle=gradient;if(navigator.appVersion.indexOf('WebKit')!=-1){context.fill();}else{context.fillRect(0,0,reflectionWidth,reflectionHeight*2);}}}}catch(e){}},remove:function(image){if(image.className=="reflected"){image.className=image.parentNode.className;image.parentNode.parentNode.replaceChild(image,image.parentNode);}}}
	function addReflections(){var rimages=document.myGetElementsByClassName('reflect');for(i=0;i<rimages.length;i++){var rheight=null;var ropacity=null;var classes=rimages[i].className.split(' ');for(j=0;j<classes.length;j++){if(classes[j].indexOf("rheight")==0){var rheight=classes[j].substring(7)/100;}else if(classes[j].indexOf("ropacity")==0){var ropacity=classes[j].substring(8)/100;}}
	Reflection.add(rimages[i],{height:rheight,opacity:ropacity});}} 