﻿var w=screen.width;
var h=screen.height;
var bgurl=null;

function fBGurl() {
	$("#txtW").val(w);
	$("#txtH").val(h);
	$.ajax({
	    url: ("/get.asp?id="+id+"&w="+w+"&h="+h),
		beforeSend: function(){ $("#WarningDiv").show();$("#tdImgInfo").html("Downloading..."); },
	    error: function(){ $("#tdImgInfo").html("Error, retry in 5 seconds...");window.setTimeout('fBGurl();', 5000); },
	    success: function(fReturnValue){
			if (fReturnValue=='(RELOAD)') {
				window.location.reload(true);
			} else {
				$("#WarningDiv").hide();
				$("#tdImgInfo").html(fReturnValue);
				bgurl="http://f.calxibe.com/bg/"+id+"_"+w+"_"+h+".jpg";
				$("#PreloadImageDiv").html("<img src='" + bgurl + "' style='width:1px;height:1px;' onload='handlePreloadImage()'></img>");
			}
	    }
	});
}

function handlePreloadImage() {
	$("body").css("background", "#050505 url('" +bgurl+ "') no-repeat fixed center top");
	$("#PreloadImageDiv").hide();
}

function setHomepage(targetButton) {
	var url = "http://frameseek.com/"+id+"/";
	var userAgent = navigator.userAgent.toUpperCase();  
	$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase()); 
    if(instr(userAgent, 'MSIE')){
		targetButton.style.behavior='url(#default#homepage)';
		targetButton.setHomePage(url);
	//	fShare();
    } else if($.browser.chrome){
		$(document).ready(function(){ $.fn.colorbox({width:"450", height:"320", close:WebText23, href:"/homepage.asp?b=chrome&id="+id+"&Cookie="+lCookie}); });
    } else if (instr(userAgent, 'FIREFOX/')){
		$(document).ready(function(){ $.fn.colorbox({width:"450", height:"220", close:WebText23, href:"/homepage.asp?b=ff&id="+id+"&Cookie="+lCookie}); });
	} else if (instr(userAgent, 'OPERA/')){
		$(document).ready(function(){ $.fn.colorbox({width:"450", height:"420", close:WebText23, href:"/homepage.asp?b=opera&id="+id+"&Cookie="+lCookie}); });
	} else if($.browser.safari){
		$(document).ready(function(){ $.fn.colorbox({width:"510", height:"420", close:WebText23, href:"/homepage.asp?b=safari&id="+id+"&Cookie="+lCookie}); });
    } else {
		$(document).ready(function(){ $.fn.colorbox({width:"450", height:"220", close:WebText23, href:"/homepage.asp?b=ff&id="+id+"&Cookie="+lCookie}); });
    }
    return false;
}

function fShare() {
    var u="http://frameseek.com/"+id+"/t/";
    var t=document.title;
    var url='http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t);
    window.open(url,'Share','location=0,status=0,scrollbars=1,width=600,height=350'); 
}
function fFeedback() { $(document).ready(function(){ $.fn.colorbox({width:"500", height:"440", close:WebText23, href:"/contact.asp?id="+id}); }); }
function fSubmit() { $(document).ready(function(){ $.fn.colorbox({width:"450", height:"350", close:WebText23, href:"/submit.asp?id="+id}); }); }
function fImgOver(fElement) { fElement.style.backgroundImage='url(http://f.calxibe.com/img/drop-shadow2.png)'; }
function fImgOut(fElement) { fElement.style.backgroundImage='url(http://f.calxibe.com/img/drop-shadow.png)'; }
function fThemes(fCatID,fPage,fID) { $(document).ready(function(){ $.fn.colorbox({width:"740", height:"530", close:WebText23, href:"/themes.asp?catid="+fCatID+"&page="+fPage+"&id="+fID}); }); }
function fTerms() { $(document).ready(function(){ $.fn.colorbox({width:"750", height:"420", close:WebText23, href:"/terms.asp"}); }); }
function switchEngine(url) {
    document.location = url + $("#q").val();
    return false;
}
function instr(haystack, needle){
    if(haystack.indexOf(needle) != -1){
        return true;
    } else{
        return false;
    }
}
