var cookie_site_name='spim.ru';
if(($.cookie('REFERRER')==null) && (document.referrer!=null) && (document.referrer.indexOf(cookie_site_name)==-1)){$.cookie('REFERRER', document.referrer,  { expires: 90, path: '/', domain: cookie_site_name, secure: false});}

function ColorBlockShow(){  ShowColor($(this).attr("cid"),$(this).attr("ci"),$(this).attr("ck"),$(this).attr("vp"));}
function ColorBlockHide(){ CloseClrPanel($(this).attr("cid"),$(this).attr("ci"));}


function ShowColor(id,idc,ck,vp)
{

idDiv = "#clrimg"+id+"_"+idc;
for(i=0;i<ck;i++){if(idc!=i)$("#clrimg"+id+"_"+i).hide();document.getElementById("colorname"+id+"_"+i).style.backgroundColor="#FFFFFF";}
CBox=document.getElementById("clrimg"+id+"_"+idc);

if(CBox!=null)
if(CBox.style.display != "block")
        {
	document.getElementById("colorname"+id+"_"+idc).style.backgroundColor="#CCCCFF";
	CBox.style.display="block";
	if(vp==1)	{
			CBox.style.top="10px";
			CBox.style.left=(-$("#clrimg"+id+"_"+idc).width()-17)+"px";
			}
	$("input:radio", "#colorname"+id+"_"+idc)[0].checked=true;
	}
else    {
	document.getElementById("colorname"+id+"_"+idc).style.backgroundColor="#FFFFFF";
	CBox.style.display="none";
	}

}

$( document ).ready( function () {

if(strpos(location.href,'listorder.php')==false)
	{
$("#basket").load("/shop/listcart.php?r="+Math.random(1000));
$("#basket").mouseover(function(){
        $("#basketin").show();
	});   
$("#basket").mouseout(function(){
	$("#basketin").hide();
    });
         }

$("input:radio").click(function() {
  z=$(this).parents()[0];
  if (!z) return;
  z=z.id.replace(/colorname/g, "");
  m=z.split(/\_/);
z=$("span", "#clrel"+m[0]);

vp=1;
if (z.parent()[0] && z.parent()[0].localName=='span')
	vp=0;
sel=0;
for(i=0;i<z.length;i++)
	{
	if(z[i].style.display!="none"){sel=1;break;}
	}
if(sel==1)
	{	
	ShowColor(m[0],m[1],z.length,vp);
	}
    });
$(".colorname").hoverIntent(ColorBlockShow, ColorBlockHide);
} );  


function ItemMinus(id)
{
$("#basket").load(encodeURI("/shop/listcart.php?action=itemminus&id="+id+"&r="+Math.random()), function() {
	$("#basketin").show();
	if(strpos(location.href,'listorder.php')!=false)location.reload();
	}
); 

return false;
}
function ItemPlus(id)
{
$("#basket").load(encodeURI("/shop/listcart.php?action=itemplus&id="+id+"&r="+Math.random()), function() {
	$("#basketin").show();
	if(strpos(location.href,'listorder.php')!=false)location.reload();
	}
); 

return false;
}


function CloseClrPanel(id,i)
{
$("#clrimg"+id+"_"+i).hide();
document.getElementById("colorname"+id+"_"+i).style.backgroundColor="#FFFFFF";
}



function ImageWindow( uri ) {
	myWin = open(uri, "linkWindow", "width=530,height=400,status=no,toolbar=no,menubar=no, titlebar=no, scrollbars=yes, resizable=yes")
}

function AddonWindow( uri ) {
	myWin = open(uri, "linkWindow", "width=800,height=700,status=no,toolbar=no,menubar=no, titlebar=no, scrollbars=yes, resizable=yes")
}


function LinkWindowWide( uri,w,h) {
	myWin = open(uri, "linkWindow", "width="+w+",height="+h+",status=no,toolbar=no,menubar=no, titlebar=no, scrollbars=yes, resizable=yes")
}

function pic(img_path,iw,ih){	
var img_alt;
var str, StrBody;
img_alt='SPIM.RU';

	str = 'resizable=yes,width=200,height=200,screenX=200,screenY=200,left=50,top=50';
	
	if (document.all){ 
		StrBody = '<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="White" onblur="self.window.close();" onresize="self.window.location.reload();">';
	} else {
		StrBody = '<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="White" onblur="self.window.close();">';
	}
		
	var win_op = window.open('','show', str);
	win_op.document.open();
	win_op.document.writeln('<html>');
	win_op.document.writeln('<head>');
	win_op.document.writeln('<title>' + del_str('<br>',' ',img_alt) + '</title>');
	win_op.document.writeln('<script>');
	win_op.document.writeln('function resize_img() {');
	win_op.document.writeln('var width = document.image.width;');
	win_op.document.writeln('var height = document.image.height;');
	win_op.document.writeln('if (!(document.all)){ self.resizeTo(width,height+61); } else { self.resizeTo((width+12),(height + 61));');
	win_op.document.writeln(' }');
	win_op.document.writeln('}');
	win_op.document.writeln('</script>');	
	win_op.document.writeln('</head>');
	win_op.document.writeln(StrBody);
	win_op.document.writeln('<img name="image" src='+ img_path + ' border=0 alt="' + del_str('<br>',' ',img_alt) + '" onload="resize_img();">');
	win_op.document.writeln('</body>');
	win_op.document.writeln('</html>');		
	win_op.document.close();
}



// Проверка броузера и установка ширины окна открываемого в нем (для фотогалереи)
browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);
var agent = navigator.userAgent;

if (agent.indexOf("Opera") > -1) {
	var send_height = 600;
	var send_width = 627;
}
else if ((browserVer >3) && (browserName == "Microsoft Internet Explorer")) {
	var send_height = 600;
	var send_width = 627;
}
else if ((browserVer >3) &&(browserName == "Netscape")) {
	var send_height = 600;
	var send_width = 624;
}



function GetCenterPosition()
{
   var send_left = (screen.availWidth / 2) - (send_width / 2);
   var send_top = (screen.availHeight / 2) - (send_height / 2);

   return "height="+send_height+",width="+send_width+",top="+send_top+",left="+send_left+",toolbar=0,scrollbars=2,resizable=no";
}
function GetCenterPosition_resize()
{
   var send_left = (screen.availWidth / 2) - (send_width / 2);
   var send_top = (screen.availHeight / 2) - (send_height / 2);

   return "height="+send_height+",width="+send_width+",top="+send_top+",left="+send_left+",toolbar=0,scrollbars=2,resizable=yes";
}



// Открытие IPIX в новом окне
function ipix_open(width, height, src, title){

    param = "width="+width+", height="+height;
    var win=window.open('','win',param);   
    win.focus();

	win.document.open();
	win.document.writeln('<html>');
	win.document.writeln('<head>');
	win.document.writeln('<title>' + title + '</title>');
	win.document.writeln('</head>');
	win.document.writeln('<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="White">');
	win.document.writeln('<OBJECT ID="IpixX1" WIDTH="'+width+'" HEIGHT="'+height+'" CLASSID="CLSID:11260943-421B-11D0-8EAC-0000C07D88CF" CODEBASE="http://www.ipix.com/viewers/ipixx.cab#version=6,0,0,2"><PARAM NAME="IPXFILENAME" VALUE="'+src+'"><EMBED SRC="'+src+'" WIDTH="'+width+'" HEIGHT="'+height+'"  BORDER=0 PALETTE="FOREGROUND" TYPE="application/x-ipix" PLUGINSPAGE="http://www.ipix.com/cgi-bin/download.cgi"></EMBED></OBJECT>');
	win.document.writeln('</body>');
	win.document.writeln('</html>');		
	win.document.close();
}

function del_str( del, rep , str  )
{
	res = str;

	while( res.search(del) >= 0  )
	{
		res = res.replace( del, rep );
	}

	return res;
}
function str_replace ( search, replace, subject ) {    // Replace all occurrences of the search string with the replacement string
    // 
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
 
    if(!(replace instanceof Array)){
        replace=new Array(replace);
        if(search instanceof Array){//If search    is an array and replace    is a string, then this replacement string is used for every value of search
            while(search.length>replace.length){
                replace[replace.length]=replace[0];
            }
        }
    }
 
    if(!(search instanceof Array))search=new Array(search);
    while(search.length>replace.length){//If replace    has fewer values than search , then an empty string is used for the rest of replacement values
        replace[replace.length]='';
    }
 
    if(subject instanceof Array){//If subject is an array, then the search and replace is performed with every entry of subject , and the return value is an array as well.
        for(k in subject){
            subject[k]=str_replace(search,replace,subject[k]);
        }
        return subject;
    }
 
    for(var k=0; k<search.length; k++){
        var i = subject.indexOf(search[k]);
        while(i>-1){
            subject = subject.replace(search[k], replace[k]);
            i = subject.indexOf(search[k],i);
        }
    }
 
    return subject;
 
}

function strpos( haystack, needle, offset){ // Find position of first occurrence of a string 
	 var i = (haystack+'').indexOf(needle, (offset || 0));
 	 return i === -1 ? false : i;
	}

