// JavaScript Document

//Preload both the images

var curStyle=getCookie("skinstyle");
if(curStyle==null)curStyle="Orange";

var images = new Array(9);
var images_hover = new Array(9);
ImagesArrFill(curStyle);

function ImagesArrFill(curStyle){
images["RacingBT"] = new Image();
images["RacingBT"].src = "images/Logo/"+curStyle+"/RacingBT.jpg"
images_hover["RacingBT"] = new Image();
images_hover["RacingBT"].src = "images/Logo/"+curStyle+"/RacingBT_Hover.jpg"
images["ShootingBT"] = new Image();
images["ShootingBT"].src = "images/Logo/"+curStyle+"/ShootingBT.jpg"
images_hover["ShootingBT"] = new Image();
images_hover["ShootingBT"].src = "images/Logo/"+curStyle+"/ShootingBT_Hover.jpg"
images["BoardBT"] = new Image();
images["BoardBT"].src = "images/Logo/"+curStyle+"/BoardBT.jpg"
images_hover["BoardBT"] = new Image();
images_hover["BoardBT"].src = "images/Logo/"+curStyle+"/BoardBT_Hover.jpg"
images["SportBT"] = new Image();
images["SportBT"].src = "images/Logo/"+curStyle+"/SportBT.jpg"
images_hover["SportBT"] = new Image();
images_hover["SportBT"].src = "images/Logo/"+curStyle+"/SportBT_Hover.jpg"
images["QuestBT"] = new Image();
images["QuestBT"].src = "images/Logo/"+curStyle+"/QuestBT.jpg"
images_hover["QuestBT"] = new Image();
images_hover["QuestBT"].src = "images/Logo/"+curStyle+"/QuestBT_Hover.jpg"
images["ActionBT"] = new Image();
images["ActionBT"].src = "images/Logo/"+curStyle+"/ActionBT.jpg"
images_hover["ActionBT"] = new Image();
images_hover["ActionBT"].src = "images/Logo/"+curStyle+"/ActionBT_Hover.jpg"
images["DressUpBT"] = new Image();
images["DressUpBT"].src = "images/Logo/"+curStyle+"/DressUpBT.jpg"
images_hover["DressUpBT"] = new Image();
images_hover["DressUpBT"].src = "images/Logo/"+curStyle+"/DressUpBT_Hover.jpg"
images["ClassicBT"] = new Image();
images["ClassicBT"].src = "images/Logo/"+curStyle+"/ClassicBT.jpg"
images_hover["ClassicBT"] = new Image();
images_hover["ClassicBT"].src = "images/Logo/"+curStyle+"/ClassicBT_Hover.jpg"
images["MultDownBT"] = new Image();
images["MultDownBT"].src = "images/Logo/"+curStyle+"/LogoBtMultDown.png"
images_hover["MultDownBT"] = new Image();
images_hover["MultDownBT"].src = "images/Logo/"+curStyle+"/LogoBtMultDown_Hover.png"
images["OnlineDownBT"] = new Image();
images["OnlineDownBT"].src = "images/Logo/"+curStyle+"/LogoBtOnlineDown.png"
images_hover["OnlineDownBT"] = new Image();
images_hover["OnlineDownBT"].src = "images/Logo/"+curStyle+"/LogoBtOnlineDown_Hover.png"


}

//Toggles the image
function changer(bt) {
if(document.images[bt].src == images[bt].src) document.images[bt].src = images_hover[bt].src 
else document.images[bt].src = images[bt].src 
}


function ChangeCat(form,id){
	new Ajax.Updater('r','Scripts/ChangeCat.php',{method:'post',evalScripts:true ,parameters: { cat:form.cat.value, id:id }});
}


 function addStyleSheet(url){
 var style;
  if (typeof url == 'undefined')
  {
    style = document.createElement('style');
  }
  else
  {
    style = document.createElement('link');
    style.rel = 'stylesheet';
    style.type = 'text/css';
    style.href = url;
  }
  document.getElementsByTagName('head')[0].appendChild(style);
  style = document.styleSheets[document.styleSheets.length - 1];
}

function getMovie(Movie) {
    var M$ =  navigator.appName.indexOf("Microsoft")!=-1
    return (M$ ? window : document)[Movie]
}

 function ChangeTitle(title){
	var tla=title.length;
  if(tla <= 14){document.getElementById("Title-Div").innerHTML = title;}
  if((tla > 14)&&(tla<=44)){
	  var width=170+(44-tla)*10;
	  getelementbyid('top-black').style.width = width+"px";
	  document.getElementById("Title-Div").innerHTML = title;}
  if(tla > 44){
	  getelementbyid('top-black').style.width = 170+"px";
	  title=title.substring(0,44);
	  document.getElementById("Title-Div").innerHTML = title;}  
	};




isNS4 = (document.layers) ? true : false;
isIE4 = (document.all && !document.getElementById) ? true : false;
isIE5 = (document.all && document.getElementById) ? true : false;
isNS6 = (!document.all && document.getElementById) ? true : false;


function getelementbyid(myid) {
   if (isNS4){
        objElement = document.layers[myid];
     }else if (isIE4) {
        objElement = document.all[myid];
     }else if (isIE5 || isNS6) {
             objElement = document.getElementById(myid);
     }
return(objElement);
} 
function ResizeBut(obj,bol){
 if(bol==true){
    obj.style.width="18px";
    obj.style.height="18px"; 
 }else if(bol==false){
    obj.style.width="20px";
    obj.style.height="20px";}  
  }



function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}



 function changestyle(style){
  setCookie("skinstyle", style, "Mon, 01-Jan-3000 00:00:00 GMT", "/");
  ImagesArrFill(style);
      if(document.images["RacingBT"])
  	 document.images["RacingBT"].src = images["RacingBT"].src;
	  if(document.images["ShootingBT"])
	 document.images["ShootingBT"].src = images["ShootingBT"].src;
	  if(document.images["BoardBT"])
	 document.images["BoardBT"].src = images["BoardBT"].src;
	  if(document.images["SportBT"])
	 document.images["SportBT"].src = images["SportBT"].src;
	  if(document.images["QuestBT"])
	 document.images["QuestBT"].src = images["QuestBT"].src;
	  if(document.images["ActionBT"])
	 document.images["ActionBT"].src = images["ActionBT"].src;
	  if(document.images["DressUpBT"])
	 document.images["DressUpBT"].src = images["DressUpBT"].src;
	  if(document.images["ClassicBT"])
	 document.images["ClassicBT"].src = images["ClassicBT"].src;
	  if(document.images["MultDownBT"])
	 document.images["MultDownBT"].src = images["MultDownBT"].src;
      if(document.images["OnlineDownBT"])
     document.images["OnlineDownBT"].src = images["OnlineDownBT"].src;
  // getelementbyid("Logo").ChangeStyle(style); //For flash logo
  if (getelementbyid("ZoomControl") != null){
   getelementbyid("ZoomControl").ChangeStyle(style);}
  addStyleSheet(style+"-Style.css");  
 }  


function GameFromHash(id){
	new Ajax.Updater('responseHTML','Scripts/gameajax.php',{method:'post',evalScripts:true ,parameters: { id:id  }});
}

var ifrate=0;
 function rate(form,id){
 if(ifrate==1){getelementbyid('rateresponse').innerHTML="<font color=\"#FF0000\">Sorry, you have already voted.</font>";}
 else{
  ifrate=1;
  var vote='';
   for(var i=0; i<=4 ; i++){
	   if(form.uvote[i].checked){vote=form.uvote[i].value;}
   }   
  if((vote==1)||(vote==2)||(vote==3)||(vote==4)||(vote==5)){new Ajax.Updater('rateresponse','Scripts/rate.php',{method:'post',evalScripts:true ,parameters: { vote:vote, id:id }});}
 else{
	 getelementbyid('rateresponse').innerHTML="<font color=\"#FF0000\">Please select your rating.</font>";
	 ifrate=0;}
 }
 }
 
 
 function ZoomIn(){
	  if (typeof getMovie("Game") != 'undefined'){
	 var curWidth=parseInt(getMovie("Game").width);
	 var curHeight=parseInt(getMovie("Game").height);
	 var Width=curWidth+10;
	 var Height=curHeight+7;
	 var Margin=parseInt(getelementbyid("top10").style.marginLeft);
	 var TopWidth=getelementbyid("top-black").offsetWidth;
	 var ControlMargin=(Width-640)/10;
	 getMovie("Game").width=Width;
	 getMovie("Game").height=Height;
	 if(Width > 640){
	 getelementbyid("ZoomControl").style.marginRight=ControlMargin*4+"px";	 
	 getelementbyid("top10").style.marginLeft=Margin-6+"px";
	 getelementbyid("top10").style.width=Width+10+"px";
	 getelementbyid("top-black").style.width=TopWidth+10+"px";}
	  }
	 }
 function ZoomOut(){
	 if (typeof getMovie("Game") != 'undefined'){
	 var curWidth=parseInt(getMovie("Game").width);
	 var curHeight=parseInt(getMovie("Game").height);
	 var Width=curWidth-10;
	 var Height=curHeight-7;
	 var Margin=parseInt(getelementbyid("top10").style.marginLeft);
	 var TopWidth=getelementbyid("top-black").offsetWidth;
	 var ControlMargin=(Width-640)/10;
	 getMovie("Game").width=Width;
	 getMovie("Game").height=Height;
	 if(Width >630){
	 getelementbyid("ZoomControl").style.marginRight=ControlMargin*4+"px";	 
	 getelementbyid("top10").style.marginLeft=Margin+6+"px";
	 getelementbyid("top10").style.width=Width+10+"px";
	 getelementbyid("top-black").style.width=TopWidth-10+"px";}
	 }
     }
 function RestoreZoom(){
	  if (typeof getMovie("Game") != 'undefined'){
	 var Width=640;
	 var Height=450;
	 var TopWidth=650-(getelementbyid("TopTitle").offsetWidth);
	 if(TopWidth>=470){TopWidth=470;}
	 getMovie("Game").width=Width;
	 getMovie("Game").height=Height;
	 getelementbyid("ZoomControl").style.marginRight="0px";
	 getelementbyid("top10").style.marginLeft="210px";
	 getelementbyid("top10").style.width=Width+10+"px";
	 getelementbyid("top-black").style.width=TopWidth+"px";
	 }
     }
 function FullScreen(){
	 if (typeof getMovie("Game") != 'undefined'){
	 var Height=450;
	 var Width=640;
	 var TopWidth=getelementbyid("top-black").offsetWidth;
	 var ClientHeight=getClientHeight();
	 var ClientWidth=getClientWidth();
	 var Margin=parseInt(getelementbyid("top10").style.marginLeft);
	 while(((Height+28)<ClientHeight)&&((Width+28)<ClientWidth)){
		 Height+=7;
	     Width+=10;
		 TopWidth+=10;
		 Margin-=6;
		 }
	 window.parent.scrollTo(0,320);
	 var ControlMargin=Math.round((Width-640)/10);
	 getMovie("Game").width=Width;
	 getMovie("Game").height=Height;
	 getelementbyid("ZoomControl").style.marginRight=(ControlMargin)*4+"px";	 
	 getelementbyid("top10").style.marginLeft=Margin+"px";
	 getelementbyid("top10").style.width=Width+10+"px";
	 getelementbyid("top-black").style.width=TopWidth+"px";	 
	 }
     }
 function getClientHeight()
 {
	if(window.innerWidth){
    height = window.innerHeight;
    }else if(document.documentElement && document.documentElement.clientWidth){
    height = document.documentElement.clientHeight;
    }else if(document.body && document.body.clientWidth){
    height = document.body.clientHeight;
    }
  return height;  
 }
 function getClientWidth()
 {
   if(window.innerWidth){
    width = window.innerWidth;
   }else if(document.documentElement && document.documentElement.clientWidth){
    width = document.documentElement.clientWidth;
   }else if(document.body && document.body.clientWidth){
    width = document.body.clientWidth;
   }	 
  return width;
 }
 function Scroll(){
	 window.parent.scrollTo(0,320);
	 }

    
 