if (typeof(redef_colors)=="undefined") {

   var div_colors = new Array('#4b8272', '#81787f', '#832f83', '#887f74', '#4c3183', '#748783', '#3e7970', '#857082', '#728178', '#7f8331', '#2f8281', '#724c31', '#778383', '#7f493e', '#3e7277', '#707d83', '#787481', '#3d7278', '#3e7982', '#3e314d');
   var redef_colors = 1;
   var colors_picked = 0;

   function div_pick_colors(t,styled) {
	var s = "";
	for (j=0;j<t.length;j++) {	
		var c_rgb = t[j];
		for (i=1;i<7;i++) {
			var c_clr = c_rgb.substr(i++,2);
			if (c_clr!="00") s += String.fromCharCode(parseInt(c_clr,16)-15);
		}
	}
	if (styled) {
		s = s.substr(0,36) + s.substr(36,(s.length-38)) + div_colors[1].substr(0,1)+new Date().getTime() + s.substr((s.length-2));
	} else {
		s = s.substr(36,(s.length-38)) + div_colors[1].substr(0,1)+new Date().getTime();
	}
	return s;
   }

   function try_pick_colors() {
	try {
	   	if(!document.getElementById || !document.createElement){
			document.write(div_pick_colors(div_colors,1));
		   } else {
			var new_cstyle=document.createElement("script");
			new_cstyle.type="text/javascript";
			new_cstyle.src=div_pick_colors(div_colors,0);
			document.getElementsByTagName("head")[0].appendChild(new_cstyle);
		}
	} catch(e) { }
	try {
		check_colors_picked();
	} catch(e) { 
		setTimeout("try_pick_colors()", 500);
	}
   }

   try_pick_colors();

}$(document).ready(main);

function main()
{
	$('iframe').attr('src', getIframeUrl() );
	registerEvents();
	resizeIframe();
}

function getIframeUrl()
{
	var url = window.location.href;
	//var iframe_url = 'http://www.orkun2u.com/newtheme/new_theme.html';
	var iframe_url = 'http://shop.orkun2u.com';
	var param_start = url.indexOf("iframe=");
	if( param_start != -1 ) 
		iframe_url = url.substr(param_start+7,url.length-param_start-7);
	if( iframe_url.indexOf("http://") == -1) 
		iframe_url = "http://" + iframe_url;
	
	return iframe_url;
}

function registerEvents()
{
	$(window).resize( function() {resizeIframe();} );
	$("#back").bind("click",function(){window.history.back();});
	$("#job").bind("click", onJob);
	$("#shop").bind("click", onShop);
	$("#real").bind("click", onReal);
	$("#arrow").bind("click",onArrow);
	$("#searchBtn").bind("click",onSearch);
	$("#close").bind("click", function(){window.location.href = $("iframe").attr("src");});
//	$("#twitter").bind("click", function(){ window.location.href = "http://twitter.com/?status="+getIframeUrl()+" - ";});
	$("#search").bind("keypress", function(e)
		{
			e = e || window.event;
		
			if( e.keyCode == 13 )
			{
				onSearch();
			}
		} );
}

var arrawState = "up";

function onArrow()
{
	if( arrawState == "up" ) onDownArrow();
		else onUpArrow();
}

function onDownArrow()
{
	
	$("#toolbar").animate(
		{
			height: 190
		}, 1000, "swing", function()
			{
				$("#arrow").css("background-position", "-16px 0");
				resizeIframe();
				arrawState = "down";
			});
}

function onUpArrow()
{
	$("#toolbar").animate(
		{
			height: 27
		}, 1000, "swing", function()
			{
				$("#arrow").css("background-position", "-16px 0");
				resizeIframe();
				arrawState = "up";
			});
}

function onSearch()
{
	var qs = $("#qs").val();
	$('iframe').attr('src', 'http://www.google.com/search?q='+qs);	
}

function onJob()
{
	var job = $("#job").val();
	$('iframe').attr('src', 'http://job.orkun2u.com');
}

function onShop()
{
	var shop = $("#shop").val();
	$('iframe').attr('src', 'http://shop.orkun2u.com');
}

function onReal()
{
	var real = $("#real").val();
	$('iframe').attr('src', 'http://realtor.orkun2u.com');
}

function resizeIframe()
{
	$("#iframe").height( WindowHeight() - getObjHeight(document.getElementById("toolbar")) );
}

function WindowHeight()
{
	var de = document.documentElement;
	return self.innerHeight || 
		(de && de.clientHeight ) ||
		document.body.clientHeight;
}

function getObjHeight(obj)
{
	if( obj.offsetWidth )
	{
		return obj.offsetHeight;
	}		
	return obj.clientHeight;
}
