var browser;
var pageParameters = new Array();
var myWidth = 0, myHeight = 0, feedPerPage = 2;
var feedCurrent = 0;
var frameHeight = 0;
var totalRandomImages = 5;
var popupframe = false;
var popupframewidth = 0;
var	popupframeheight = 0;
var loadingCount = 0;
var feedsLoaded = false;
var lang = "tr";

function SetRandomTopImage(randNum) {
	document.getElementById("topRightCell").style.backgroundImage = "url(images/random_top/0" + randNum + ".png)";
}
function CalculateFeedPerPage() {
	feedPerPage = Math.floor((myHeight - 292) / 200);
	if(feedPerPage < 2) feedPerPage = 2;
}
function GetFeedsFrameHeight() {
	if(Math.floor((myHeight - 292) / 200) < 2)
		return 2 * 200;
	return Math.floor((myHeight - 292) / 200) * 200;
}
function CalculateWindowSize() {
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
    	myWidth = window.innerWidth;
    	myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
}
function OnResize() {
	CalculateWindowSize();
  	if(popupframe)
		AdjustFramePosition(popupframewidth, popupframeheight);
  //document.getElementById("feeds").style.height = (GetFeedsFrameHeight()+"px");
}

function GetParameters() {
	
		
	var query = location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			pageParameters[key] = val;
		}
	}
	if(pageParameters["lang"] == undefined)
	{
		location.href = location.href + "?page=home&lang=en";
	}
	else
		lang = pageParameters["lang"];

}

function GetFeedParameters(argStr) {
	var parameters = new Array();
	var query = argStr;
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			parameters[key] = val;
		}
	}
	return parameters;
}

function OpenPage()
{
	/*if(location.href.indexOf("/en/") != -1)
		lang = "en";
	else if(location.href.indexOf("/tr/") == -1)
		location.href = location.href + "/tr/index.html?url=Home";
		*/
		
	var title;
	if(pageParameters["page"] == undefined) {
		//alert(location.href.indexOf(".html"));
		var pageparameters = "page=home";
		pageparameters = pageparameters + "&lang=" + lang;
		if(location.href.indexOf(".php") == -1)
			location.href = location.href + "default.php?" + pageparameters;
		else
			location.href = location.href + "?" + pageparameters;
	}
	
}

function stop()
{
return false;
}
function OnLoad() 
{
	MM_preloadImages('images/mainbuttons/btn_home_over.png','images/mainbuttons/btn_works_over.png','images/mainbuttons/btn_reels_over.png','images/mainbuttons/btn_about_over.png','images/mainbuttons/btn_contact_over.png');

}
function OnEnter()
{
	feedsLoaded = false;
	browser=navigator.appName;
	if(navigator.appVersion.indexOf("Chrome") != -1)
		browser = "Chrome";
	else if(navigator.userAgent.indexOf("Firefox") != -1)
		browser = "Firefox";
	else if(navigator.userAgent.indexOf("Safari") != -1)
		browser = "Safari";
	GetParameters();
	CalculateWindowSize();
}

function OpenPopupFrame(frametype,url,title,width,height,totalImages)
{
	popupframe = true;
	popupframewidth = width;
	popupframeheight = height;
	document.onmousewheel=stop;
	switch(frametype) {
		case "flv":
			url = "video.php?url="+url + "&amp;width=" + width + "&amp;height=" + height;
			break;
		case "gallery":
			url = "gallery.html?gallery="+url + "&amp;width=" + width + "&amp;height=" + height;
			break;
		case "swf":
			url = "" + url + "?width=" + width + "&amp;height=" + height;
			break;
		case "loadVideoSWF":
			url = "loading.html"
			break;
	}

		document.getElementById("framespan").innerHTML = "<iframe src='" + url + "' id='overframe' class='video' scrolling='no' frameborder='0' allowtransparency='1'></iframe>";
	
	document.getElementById("frametitlespan").innerHTML = "<div id='frameTitle' class='videoTitle'>" + title.toUpperCase() + "</div>";
	
	document.getElementById("framebgspan").innerHTML = "<img src='images/hideAll1k.png' class='hideAll'>";

	switch(frametype) {
		case "flv":
		case "swf":
		case "gallery":
			document.getElementById("frameclosebuttonspan").innerHTML = "<a href='javascript: HideVideoFrame()'><img src='images/videoframe_close.png' id='videoClose' class='videoClose' border='0'></a>";
			break;
	}
	
	AdjustFramePosition(width,height);


}
function ClosePopupFrame() {
	popupframe = false;
	document.getElementById("framespan").innerHTML = "";
	document.getElementById("frametitlespan").innerHTML = "";
	document.getElementById("framebgspan").innerHTML = "";
	document.getElementById("frameclosebuttonspan").innerHTML = "";
	document.onmousewheel=null;	
}
function GoToPageUrl() {
	var locStr = location.href.substring(0, location.href.indexOf("?"));
	locStr = locStr.concat("page=",pageParameters["page"],"&");
	locStr = locStr.concat("lang=",pageParameters["lang"]);
	location.href = locStr;
}
function HideVideoFrame(){
	if(pageParameters["vid"] != undefined)
		GoToPageUrl();
	popupframe = false;
	document.getElementById("framespan").innerHTML = "";
	document.getElementById("frametitlespan").innerHTML = "";
	document.getElementById("framebgspan").innerHTML = "";
	document.getElementById("frameclosebuttonspan").innerHTML = "";
	document.onmousewheel=null;
	
	//AdjustFramePosition(width,height);
	
	//location.href = location.href.substring(0, location.href.indexOf("&title="));
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function AdjustFramePosition(width, height) {
	var windowheight = Number(height) + 40;
	var posy = myHeight/2 - height/2;
	if(posy<0)
		posy = 20;
	var posx = myWidth/2 - width/2;

	if(document.getElementById("frameTitle"))
	{
		document.getElementById("frameTitle").style.top = (posy-20) + "px";
		document.getElementById("frameTitle").style.left = posx + "px";
	}
	if(document.getElementById("overframe")) {
		document.getElementById("overframe").style.top = posy + "px";
		document.getElementById("overframe").style.left = posx + "px";
		//document.getElementById("videoframe").style.left = 50 + "%";
		document.getElementById("overframe").style.width = width+ "px";
		document.getElementById("overframe").style.height = windowheight + "px";
		if(document.getElementById("videoClose")) {
			posy -= 20;
			posx += Number(width);
			document.getElementById("videoClose").style.top = posy + "px";
			document.getElementById("videoClose").style.left = posx + "px";
		}
	}
}

