window.onresize = function(){
//	resizeCenterCanvas();
};
function resizeCenterCanvas() {
	var win_size = getWindowSize();
	var canvas = document.getElementById("center_content");
	var min_height = 200;
	var offset = 240;
	var canvas_height = win_size[1]-offset>min_height?win_size[1]-offset:min_height;
	canvas.style.height = canvas_height+"px";
}
function getWindowSize() {
	var myWidth = 0, myHeight = 0;
	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;
	}
	return [myWidth, myHeight];
}
function resolveWindowLocation(){
	var window_location = window.location.href;
	if(window_location.indexOf("#")>-1){
		window_location = window_location.split("#/");
		window.location = server_url+window_location[window_location.length-1];
		hash = location.hash;
		return false;
	}else{
		document.getElementById("right_content_loading").style.display="none";
		document.getElementById("right_content").style.display="block";
	}
}
function doInit() {
//	resizeCenterCanvas();
	resolveWindowLocation();
	init();
}
function resolveHeight(){
	try{
		var ch = document.getElementById("complete_height");
	}catch(err){return};
	if(!ch) return;
	var ii = document.getElementById("item_images");
	var id = document.getElementById("item_detailes");
	var off = ii.offsetHeight-id.offsetHeight;
	var ci1 = document.getElementById("complete_item_images1");
	var ci2 = document.getElementById("complete_item_images2");
	var bi = document.getElementById("bigImg");
	var bih = document.getElementById("big_img_holder");
	bi.style.visibility = "hidden";
	if(!bi.complete){
		setTimeout(function(){resolveHeight()},1);
		return;
	}
	MojoZoom.init();
	initColorbox();
	bih.className="big_img_holder_off ui-corner-top";
	bi.style.visibility = "visible";
	if(off>0){
		ch.style.height = ch.offsetHeight+off+"px";
	}else{
		if(off!=0){
			ci1.className = "complete_item_image ui-corner-top";
			bih.className="big_img_holder_off";
			bi.className = "complete_item_image";
			ci1.style.height = (off/-2)+"px";
			ci2.style.height = (off/-2)+"px";
		}
	}
	off = ii.offsetHeight-id.offsetHeight;
}
function init() {
	if (document.getElementsByTagName) {
		var links = document.getElementsByTagName("a");
		for (var i=0; i < links.length; i++) {
			if(links[i].className.match(/hijax_link/gi)){
				links[i].onclick = function(){
					this.canvasId = "canvas_content";
					var file = this.getAttribute("href");
					file = file.split(server_url);
					file = file[file.length-1];
					file = file.split("?")[0];
					this.file = file;
					var data = this.getAttribute("href").split("?")[1]+"&rk="+Get_Cookie("config_rk");
					this.data = data;
					return (!sendData(this));
				}
			}
		}
	}
	resolveHeight();
	resolveTitleLinks();
	var win_location = window.location.href.split("/");
	win_location = win_location[win_location.length-1].replace(/\-/g, "").toLowerCase();
	if(win_location=="datepersonale" || win_location=="adresadelivrare"){
		checkJudetOras();
	}
}
function preloadCanvas(canvasId) {
	var li = document.getElementById('loading_img');
	li.style.display = "block";
}
var back_link="haine-dama";
function sendData(href) {
	back_link=location.hash;
	try{
		title_div.remove();
	}catch(err){};
	var data = href.data;
	var canvasId = href.canvasId;
	preloadCanvas(canvasId);
	$.ajax({
		type: "POST",
		url: server_url+"ajaxPhp/"+href.file,
		data: data,
		success: function(msg){
			parseResponse(msg,href);
		}
	});
	return true;
}
function parseResponse(msg,href) {
	var canvasId = href.canvasId;
	var win_location = window.location.href.split("/");
	if(win_location[win_location.length-1] != href.file){
		window.location = "#/"+href.file;
		hash = location.hash;
	}
	var li = document.getElementById('loading_img');
	li.style.display = "none";
	var response = msg.split(Get_Cookie("config_rk"));
	document.getElementById(canvasId).innerHTML = response[0];
	document.getElementById("path").innerHTML = response[1];
	document.title = response[3]+"Haine Dama | Haine Femei | Haine";
	if(response[4]!=undefined){
		document.getElementById("content_bottom").style.display = "block";
		displayBottomContent();
	}else{
		document.getElementById("content_bottom").innerHTML = "";
		document.getElementById("content_bottom").style.display = "none";
	}
	if(href.doreload!=-1){
		$("#dialog").dialog('close');
		removeElement("dialog");
	}
	setSelectedLink();
	init();
	
	$("#email_nl_err").hide();
}
function setSelectedLink(){
	var win_location = window.location.href.split("/");
	win_location = win_location[win_location.length-1].replace(/\-/g, "").toLowerCase();
	win_location = win_location==""?"hainedama":win_location;
	win_location = win_location=="adresadelivrare"||win_location=="datepersonale"||win_location=="schimbaparola"?"contulmeu":win_location;
	if (document.getElementsByTagName) {
		var links = document.getElementsByTagName("a");
		for (var i=0; i < links.length; i++) {
			var a_location = links[i].href;
			a_location = a_location.replace(/\-/g, "").toLowerCase();
			a_location = a_location.replace(/hainedama.com/g, "");
			if(links[i].className == "hijax_link left_menu ui-corner-all" || links[i].className == "hijax_link left_menu_selected ui-corner-all" || links[i].className == "hijax_link top_menu ui-corner-all" || links[i].className == "hijax_link top_menu_selected ui-corner-all" || links[i].className == "ui-corner-top hijax_link top_menu"){
				var cname = links[i].className.search("left_menu")>-1?"left_menu":"top_menu";
				var corner_class = links[i].className.search("ui-corner-top")>-1?"ui-corner-top":"ui-corner-all";
				if(a_location.search(win_location)>-1){
					links[i].className = "hijax_link "+cname+"_selected "+corner_class;
				}else{
					links[i].className = "hijax_link "+cname+" "+corner_class;
				}
			}
		}
	}
}
var IE = document.all?true:false
$(window).load( function() {
	if (!IE) document.captureEvents(Event.MOUSEMOVE)
	document.onmousemove = getMouseXY;
	doInit();
	setSelectedLink();
	if(document.getElementById("content_bottom").innerHTML!=""){
		document.getElementById("content_bottom").style.display="block";
		displayBottomContent();
	}else{
		document.getElementById("content_bottom").style.display="none";
	}
	$.ajax({
		type: "POST",
		url: server_url_v2+"generateSitemap.php",
		data: "",
		success: function(msg){
		}
	});
});
function initColorbox(){
	$("a[rel='photo_hainedama']").colorbox();
}
function hideHelper(){
	$("#img_help").hide("blind", 10);
}
function showHelper(){
	$("#img_help").show("blind", 10);
}
var xMouse = 0;
var yMouse = 0;
function displayBottomContent(){
	$.ajax({
		type: "POST",
		url: server_url_v2+"getBottomContent.php",
		data: "",
		success: function(msg){
			$("#content_bottom").html(Base64.decode(msg));
		}
	});
}
function ajaxReload(){
	var obj = new Object();
	obj.canvasId = "canvas_content";
	var file = window.location.href;
	file = file.split(server_url);
	file = file[file.length-1];
	file = file.split("?")[0];
	if(file.indexOf("#")>-1){
		var tmp = file.split("#/");
		file = tmp[tmp.length-1];
	}		
	obj.file = file;
	var data = window.location.href.split("?")[1]+"&rk="+Get_Cookie("config_rk");
	obj.data = data;
	obj.doreload = -1;
	sendData(obj);
}
var hash = location.hash;
$(window).load( function () { setHashChanged(); } );
function setHashChanged(){
	setInterval(function()
	{
		if (location.hash != hash)
		{
			ajaxReload();
			hash = location.hash;
		}
	}, 100);
//	tweetmeme_url = 'http://www.haniedama.com';
//	tweetmeme_style = 'compact';
}