var zoomEnabled = true;

  

$(document).ready(function()
{

	$("#mainstyleimagelink").jqzoom({
	   		zoomWidth: 400,zoomHeight: 600, title:false});
	$(".zebra tr:even td").css("background", "#eee");
	$("#inp_style").keypress(function(event)
	{
		if (event.keyCode == 13)
			startSearch();
	});

	$(".coll_img").each(function()
	{
		$("#rdbfixer").append(
			"<a href='"+$("#"+$(this).attr("id")+"_link").attr("href")+"'><img src='/img/b_coll.gif' class='coll_roundfixer' style='border:1px solid white;left:"+$(this).offset().left+"px;top:"+$(this).offset().top+"px;' /></a>"
		);
	});
	$("#bigmainimg").each(function()
	{
		var rndfix = "";
		var coords = [];
		coords[0] = [$(this).offset().left, $(this).offset().top];
		coords[1] = [$(this).offset().left + $(this).width()-10, $(this).offset().top];
		coords[2] = [$(this).offset().left-10 + $(this).width(), $(this).offset().top+$(this).height()-10];
		coords[3] = [$(this).offset().left, $(this).offset().top+$(this).height()-10];
		for (var i = 0; i < coords.length; i++)
		{
			rndfix+="<img src='/img/s"+(i+1)+".gif' class='style_roundfixer' style='left:"+coords[i][0]+"px;top:"+coords[i][1]+"px;' />";
		}	
		$("#rdbfixer").append(
			rndfix
		);
	});
	$(".alt_img_img").each(function()
	{
		$("#rdbfixer").append(
			"<a href=\""+$("#"+$(this).attr("id")+"_link").attr("href")+"\"><img src='/img/b_alt.gif' class='alt_roundfixer' style='border:1px solid white;left:"+$(this).offset().left+"px;top:"+$(this).offset().top+"px;' /></a>"
		);
	});
	$(document).pngFix();
});
RDTimeout = null;
function changeMainImage(style_no, pic)
{
	$("#mainstyleimagelink").replaceWith("<a href='/img/styles/"+style_no+"/"+pic+"' title='BlushProm Style #"+style_no+"' onclick='return false;' id='mainstyleimagelink'><img src='/img/styles/"+style_no+"/main/"+pic+"' border='0'  id='bigmainimg'  height='600' width='400' /></a>");
	zoomEnabled = true;
	$("#mainstyleimagelink").jqzoom({
	    zoomWidth: 400,zoomHeight: 600, title:false});
}
function startZoom()
{
	if ((!$.browser.safari) && (zoomEnabled))
	{
		zoomEnabled = false;
		$("#mainstyleimagelink").jqzoom({
	    zoomWidth: 400,zoomHeight: 600, title:false});
	}
}
function zoomPopup()
{
	var popup = window.open("", "zoompopup", "status=0,scrollbars=yes,location=0");
	popup.document.write("<img src='"+$("#mainstyleimagelink").attr("href")+"' /><div style='position:absolute;width:1200px;height:1800px;left:0px;top:0px;'><img src='/img/blank.gif' width='1200' height='1800' /></div>");
}
function sendEmail()
{
	data={};
	data.to = $("#sendEmailTo").val();
	data.text = $("#sendEmailText").val();
	$.post("/email.php", data, function(data)
	{
		if ($.trim(data) == "success")
		{
			alert("Your message has been successfully sent.");
			$('#email_holder').fadeOut('fast');
		}
		else
		{
			alert(data);
		}
	});
}
function ChangeAlt(newa)
{
	$("#bigmainimg").attr("src", newa);
}
function showSwatchHolder(cols)
{
	if (cols==2){ w=460; } else { w=300; }
	swWindow = window.open("", "swatches", "status=no,scrollbars=no,toolbar=no,location=no,menubar=no,width="+w+",height=520,left=250,top=100");
	swWindow.document.open("text/html", "replace");
	swWindow.document.write('<HTML><head><title>Swatch Card</title></head><BODY>'+$("#sw_card_holder").html()+"</BODY></HTML>");
	swWindow.document.close();
}
function startSearch()
{
	if($.trim($("#inp_style").val())!="")
	{
		$.get("/index.php?action=check_style_exist&name="+$.trim($("#inp_style").val()),
			{},
			function(data)
			{
				if ($.trim(data) == "exist")
					onStartSearch()
				else
					$("#inp_style").val("not found...");
			});
	}
}
function onStartSearch()
{
	window.location.href="/styles/"+$("#inp_style").val();
}
