/**
 * Hide links
 */
 /*
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", OnPageLoad, false);	
} else {
	window.addEvent("domready", function () {alert(1)});
}
*/

function showErrorMessage() {
alert(2);	

var errorText =
	'<div id="dialog" class="pop-up-win2" style="display:none"><h3>:</h3>'+
	'<div class="what_need-msg"><p>Hello!</p></div><div class="we_do-choise">'+
	'<a onclick="Lightview.hide();return false;" style="float: right;" class="btn btn_close" href="/shop/basket"/></div></div>';
alert(3);	
jQuery('body').append(errorText);
alert(4);	
	Lightview.show('#dialog');
}

Events.attach(window, "load", OnPageLoad);

function OnPageLoad() {
	
	var tags = ['a', 'div'];

	for(var j=0; j<tags.length; j++) 
	{
		var elementsByTag = document.getElementsByTagName(tags[j]);

		if(elementsByTag!=null) 
		{
			var elementsByTagToActivate=new Array();	  

			if(!elementsByTag.length) {
				var elementsByTag_ = new Array();
				elementsByTag_[0] = elementsByTag;
				elementsByTagToActivate = elementsByTag_;
			} else {
				elementsByTagToActivate = elementsByTag;
			}

			for(var i=0;i<elementsByTagToActivate.length;i++) {
				var current = elementsByTagToActivate[i];
				if(current.id=='waitLoad') {
					//current.style.display='block';  
					current.style.visibility='visible';
				}	    	
			} 
		}
	}

	var elementsByTag = document.getElementsByTagName('ul');

	if(elementsByTag) {
		var elementsByTagToActivate=new Array();	  

		if(!elementsByTag.length) {
			elementsByTagToActivate = new Array(elementsByTag);
		} else {
			elementsByTagToActivate = elementsByTag;
		}

		var reg = /FlowerOfTime_\d+_(\d+)/i;

		for(var i=0; i<elementsByTagToActivate.length; ++i) {
			var d = reg.exec(elementsByTagToActivate[i].id);
			if( d ) {
				new FlowerOfTime(elementsByTagToActivate[i].id, d[1], 86400000, ULOfTime);
			}	    	
		}
	}

	var divs = document.getElementsByTagName("div");
		
	var dialogRE = /dialog/; // Any alert window
	var terrorRE = /none/;
	/*var terrorRE = /t-error/; */// Tapestry validation errors
	var popupRE = /pop-up-win2/; // Pop-ups excepting Waitnglist
	var popupActRE = /pop-up-win3/; // Campaign change warning
	for (var i = 0; i < divs.length; i++) {
	
		var div = divs[i];
		
		if ( popupRE.test(div.className) || popupActRE.test(div.className) || dialogRE.test(div.className) || terrorRE.test(div.className) ) {
						
			if(popupActRE.test(div.className)) {
				div.id="dialog";				
				div.style.display = "none";
			} else {			
				if (div.id=="") {
					var header = document.createElement("h3");
					var headerText = document.createTextNode("Внимание:");
					div.firstChild.className="o-msg";
					div.insertBefore(header, div.firstChild);
					
					//div.appendChild(header,div.firstChild);
									
					header.appendChild(headerText);				
					div.id="dialog";				
					div.style.display = "none";				
					var ok = document.createElement("div");
					ok.className = "we_do-choise";
					var a = document.createElement("a");
					a.style.float="right";
					a.className="btn btn_close";
					a.href = "javascript: void(0)";
					a.onclick = ___hide;
					//a.appendChild(document.createTextNode("Закрыть"));
					ok.appendChild(a);			
					div.appendChild(ok);					
				}
			}
			div.className = "pop-up-win2";
			Lightview.show({ href: "dialog", rel: 'inline', width: 500, height: 200, autosize: false});
			
			break;		
		}
	}
}

function ___hide(a) {
	a.href="#dummy";
	Lightview.hide();
	return false;
}

/**
 * Shop details viewer
 */

var lock = false; 

function releaseLock() {
	lock = false; 
} 
 
ShopDetailsViewer = {
	hoverhandler:null,
	spanRE:/span/i,
	imgRE:/img/i,
	init:Events.attach(window, "load", function() {
		ClickHandler.addHandler("enlarge", ShopDetailsViewer.enlarge);
		var viewer = document.getElementById("detailViewer");
		ShopDetailsViewer.hoverhandler = Events.attach(viewer, "click", ShopDetailsViewer.hover);
		Events.detach(ShopDetailsViewer.init); //cleanup
	}),
	hover:function(e) {
		
	    var zoomMode = "jqzoom"; 
	    var zoomOptions = options;
	    
		var e = e||event;
		
		target = e.target||e.srcElement;
		
		if (ShopDetailsViewer.spanRE.test(target.nodeName)) {
			var target = target.nextSibling;
		}
		
		if (ShopDetailsViewer.imgRE.test(target.nodeName)) {
			if(lock==true) {
				return;
			}
			
			lock = true;
			var images = document.getElementsByTagName("img");
			for(var i=0;i<images.length;i++) {
				var currentImg = images[i];
				if(currentImg.id!="previewImg") {
					continue;
				}				
				var expectedLargeImageSrc = target.src.replace("tmb", "detail");				
				if(currentImg.src==expectedLargeImageSrc) {
					currentImg.parentNode.className='lightview showBlock ' + zoomMode;
					currentImg.parentNode.style.display='block';					
				} else {
					currentImg.parentNode.className='hideBlock';
					currentImg.parentNode.style.display='none';
				}	
			}		
			$j("."+zoomMode).jqzoom(zoomOptions);
			/*
			
			var prevImg = document.getElementById("previewImg");
			
			//If the name-structure of the images changes, this is the place to alter the JS-code accordingly...
			prevImg.src = target.src.replace("tmb", "detail");			
			prevImg.parentNode.href = target.src.replace("tmb", "original");
			
			*/
			
			setTimeout('releaseLock()', 200);
		}

	},
	enlarge:function(target) {
		var win = window.open("about:blank", "b4fgallery", "menubar=0,location=0,toolbar=0,personalbar=0,status=0,scrollbars=0,width=150,height=150");
		var content = "<html><head><title>kupivip.ru</title></head><body style=\"width: 100%; height: 100%; overflow: hidden;\">"
		content += "<img onclick=\"window.close()\" src=\"" + target.href + "\" />";
		content += "<script>" +
				"window.onload = function() {" +
				" var body = document.getElementsByTagName(\"body\")[0];" +
				" var img = document.images[0];" +
				" var width = img.width + (150 - body.offsetWidth);" +
				" var height = img.height + (150 - body.offsetHeight);" +
				" if (width < img.width) width = img.width+20;" + //Firefox statusbar-bug might prevent me from making a correct guess
				" if (height < img.height) height = img.height;" + // set correct height for safari
				" window.resizeTo(width, height);" +
				"};" +
				"</script>";
		content += "</body></html>"
		win.document.open("text/html");
		win.document.write(content);
		win.document.close();
		return true;
	}
}

/*
 * CountDownTimer
 *
StartCountDown("clock1",
    "<br/><br/>%%D%% Tag(e)<br/>%%H%% : %%M%% : %%S%%",
    "geloescht",
    "06/28/2010 13:27:00 -0000",
    "06/27/2010  1:27:00 -0000")
StartCountDown("clock2",
    "<br/><br/>%%H%% : %%M%% : %%S%%",
    "<br/><br/>beendet",
    "06/27/2010  2:00:00 -0000",
    "06/27/2010  1:59:50 -0000")
*/
/*
 Author:        Robert Hashemian (http://www.hashemian.com/)
 Modified by:	Munsifali Rashid (http://www.munit.co.uk/)
 Modified by:	Tilesh Khatri
 Modified by:	Jens Breitenstein
 "06/28/2010 10:27:00 PM -0000"
 */

function StartCountDown(myDiv, myDisplayFormat, myEndMessage, myTargetDate, currentServerDate)
{
    var dthen = new Date(myTargetDate);
    var dnow = new Date(currentServerDate);
    ddiff = new Date(dthen - dnow);
    gsecs = Math.floor(ddiff.valueOf() / 1000);
    CountBack(myDiv, gsecs, myDisplayFormat, myEndMessage);
}

function Calcage(secs, num1, num2)
{
    s = ((Math.floor(secs / num1)) % num2).toString();
    if (s.length < 2) {
        s = "0" + s;
    }
    return (s);
}

function CountBack(myDiv, secs, myDisplayFormat, myEndMessage)
{
    var DisplayStr = myDisplayFormat.replace(/%%D%%/g, Calcage(secs, 86400, 100000));
    DisplayStr = DisplayStr.replace(/%%H%%/g, Calcage(secs, 3600, 24));
    DisplayStr = DisplayStr.replace(/%%M%%/g, Calcage(secs, 60, 60));
    DisplayStr = DisplayStr.replace(/%%S%%/g, Calcage(secs, 1, 60));
    if (secs > 0) {
        document.getElementById(myDiv).innerHTML = DisplayStr;
        setTimeout("CountBack('" + myDiv + "'," + (secs - 1) + ",'" + myDisplayFormat
            + "', '" + myEndMessage + "');", 990);
    } else {
        document.getElementById(myDiv).innerHTML = myEndMessage;
    }
}

/**
 * WaitingList
 */

ClickHandler.addHandler("open_waitinglist_popup", function(target) {
	var id = target.href;
	id = id.substr(id.indexOf("#") + 1);
	var node = $(id);
	if (node) {
		
		if (node.getStyle("display") != 'block') {
			if (this.currentDialog) {
				ClickHandler.handlers["close_waitinglist_popup"](this.currentDialog);
			}
			node.style.display = "block";
			
			//Let's figure out if the user can 'see' the dialog.
			var nt = node.cumulativeOffset().top;
			var nb = nt + node.offsetHeight;
			var sc = (document.documentElement||document.body)
			var sp = sc.scrollTop;
			var spb = sp + sc.clientHeight;
			if (nt < sp) { //top is cut of, should be rare with the dialog positioned next to the info
				node.scrollTo();
			} else if (nb > spb) { //bottom is cut of, let's determine how far to move, if at all
				var offset = nb - spb;
				sc.scrollTop = (sp + offset > nt)?nt:(sp + offset);
			}
		} else {
			ClickHandler.handlers["close_waitinglist_popup"](this.currentDialog);
		}
	}
	this.currentDialog = target;
	return true;
});

ClickHandler.addHandler("close_waitinglist_popup",function(target) {
	var id = target.href;
	id = id.substr(id.indexOf("#") + 1);
	var node = document.getElementById(id);
	if (node && !node.isFolding) {
			node.style.display = "none";
	}
	ClickHandler.handlers["open_waitinglist_popup"].currentDialog = null;
	return true;
});


/**
 * Shop past
 */
ShopPastHelper = {
	init:Events.attach(window, "load", function() {
		if (ClickHandler) ClickHandler.addHandler("teaser", ShopPastHelper.teaser);
		Events.detach(ShopPastHelper.init); //cleanup
	}),
	teaser:function(target, size) {
		var x = size?size.x:400;
		var y = size?size.y:288;
		var win = window.open("about:blank", "b4fgallery", "menubar=0,location=0,toolbar=0,personalbar=0,status=0,scrollbars=0,width=150,height=150");
		var content = "<html><head><title>Brands4friends.de</title></head><body style=\"width: 100%; height: 100%; overflow: hidden;\">"
		content += "<script>" +
				"window.onload = function() {" +
				" var body = document.getElementsByTagName(\"body\")[0];" +
				" var width = " + x + " + (150 - body.offsetWidth);" +
				" var height = " + y + " + (150 - body.offsetHeight);" +
				" window.resizeTo(width, height);" +
				" window.location.href = \"" + target.href + "\";" + 
				"};" +
				"</script>";
		content += "</body></html>"
		win.document.open("text/html");
		win.document.write(content);
		win.document.close();
		return true;
	}
}

function openNewWindow(URLtoOpen, windowName, windowFeatures) {
	var features = windowFeatures?windowFeatures:"";
  	ShopPastHelper.teaser(URLtoOpen, {x:600,y:400}, features);
}

/**
 * Flower of time
 *
 * This is a helper to make the 'Flower of Time' dynamically
 * countdown it's clock...
 * @author Martin Reurings
 * @constructor
 * @requires Events
 * @depends events.js
 * @param {String} id The id of the node that will be used for rendering in.
 * @param {Integer} millies The amount of millisecond towards which the clock runs.
 * @param {Integer} bignum The largest time-amount to be calculated, week, day, hour or second. For numeric values see FlowerOfTime.DURATION[]
 * @param {Function} render An optional alternate rendering function, in case this class is used for a different html-construct.
 **/
function FlowerOfTime(id, millies, bignum, render) {
	this.flower = document.getElementById(id);
	if (this.flower == null) alert("464F54.001: Flower cannot be initiated, id '" + id + "' cannot be found!");
	var now = new Date();
	var millisek = parseInt(millies);	
	this.doom = new Date(now.getTime() + millisek);
	this.bignum = bignum || this.DURATION.week;
	this.render = render || this.defaultRender;
	//Render the first time
	this.render(this.difference(this.bignum));
	var self = this;
	var timer = window.setInterval(function() {
		self.showtime();
	}, this.DURATION.second * 1);
	var cleanup = Events.attach(window, "unload", function() {
		window.clearInterval(timer);
		Events.detach(cleanup);
	});
};

FlowerOfTime.prototype = {
	/**
	 * Time related constants.
	 */
	DURATION:{
		second:1000,
		minute:60000,
		hour:3600000,
		day:86400000,
		week:604800000
	},
	/**
	 * Div that returns an integer value instead of float.
	 * @param {Integer} a The number that is to be divided.
	 * @param {Integer} b The divider.
	 * @return An integer that is the whole number without fraction, not rounded down.
	 * @private
	 */
	ntgr:function(a, b) {
		var m = a % b;
		return (a - m) / b;
	},
	/**
	 * Calculate and return the difference between now and 'doom'.
	 * Returns a wrapper of the same structure as this.DURATION.
	 * @param {Integer} bignum The largest time-amount to be calculated, week, day, hour or second. For numeric values see FlowerOfTime.DURATION[]
	 * @return A 'Duration' object containing the remaining weeks/days/hours/minutes/seconds and millies.
	 */
	difference:function(bignum) {
		var now = new Date();
		var dif = this.doom.getTime() - now.getTime();
		//weeks
		if (bignum >= this.DURATION.week) {
			var weeks = this.ntgr(dif, this.DURATION.week);
			dif = dif % this.DURATION.week;
		}
		//days
		if (bignum >= this.DURATION.day) {
			var days = this.ntgr(dif, this.DURATION.day);
			dif = dif % this.DURATION.day;
		}
		//hours
		if (bignum >= this.DURATION.hour) {
			var hours = this.ntgr(dif, this.DURATION.hour);
			dif = dif % this.DURATION.hour;
		}
		//minutes
		if (bignum >= this.DURATION.minute) {
			var minutes = this.ntgr(dif, this.DURATION.minute);
			dif = dif % this.DURATION.minute;
		}
		//seconds
		if (bignum >= this.DURATION.second) {
			var seconds = this.ntgr(dif, this.DURATION.second);
			dif = dif % this.DURATION.second;
		}
		
		return {
			second:seconds,
			minute:minutes,
			hour:hours,
			day:days,
			week:weeks,
			millies:dif
		}
	},
	/**
	 * Calculate the difference and call the render method.
	 */
	showtime:function() {
		var dif = this.difference(this.bignum);
		this.render(dif);
	},
	/**
	 * The default rendering method.
	 * @argument {Duration} dif The duration until point 0 pre-calculated in weeks/days/hours/minutes/seconds
	 * @private
	 */
	defaultRender:function(dif) {
		var el = this.flower;
		var node = document.createTextNode(dif.hour + ":" + dif.minute + ":" + dif.second);
		el.replaceChild(node, el.lastChild);
	}
};

/**
 * Rendering method for FlowerOfTime based on the implementation in B4F.
 * @argument {Duration} dif The duration until point 0 pre-calculated in weeks/days/hours/minutes/seconds
 */
function ULOfTime(dif) {
	var el = this.flower;
	
	if(el.style.display=='none') {
		el.style.display='block';
	}
	
	var times = el.getElementsByTagName("li");
	var nrSwap = function (srcNode, nr, f) {
		var re = /^\d+([^\d]+)$/;
		if((nr < 10) && !f) nr = "0" + nr;
		if(!f) nr = ":" + nr;
		
		var node = document.createTextNode(nr);
		srcNode.replaceChild(node, srcNode.firstChild);
	}
	//days
	times[0] && nrSwap(times[0], dif.day, 1);
	//hours
	times[1] && nrSwap(times[2], dif.hour, 1);
	//minutes
	times[2] && nrSwap(times[3], dif.minute);
	//seconds
	times[3] && nrSwap(times[4], dif.second);
}

/**
 * Shop compact directory
 */
/**
 * ShopCompactDirectory helper to make the compact directory javascripted so that
 * it looks pretty ;)
 * 
 * @author: Martin Reurings
 * @copyright: brands4friends
 * @constructor
 * @argument {List<String, Object>} args A List of arguments
 */

function ShopCompactDirectoryHelper(args) {
	if (this.reporter && !this.reporter.className) {
		this.reporter.parentNode.className = "reporterLogger";
		document.body.appendChild(this.reporter.parentNode);
	}
	var self = this; //Circular reference, cleanup must cleanup all events created in this method!
	//Calculate the regions for the directory's animation speed.
	var normal = Math.round((100 - (args.stop||33)) / 2);
	var FR = args.fast||10;
	var R = normal;
	var FF = 100 - FR;
	var F = 100 - R;
	//Store the calculated regions.
	this.regions = {FR:FR,R:R,F:F,FF:FF};
	//'Lazy' initialisation, waits until page finished loading before attempting to attach events etc.
	var init = Events.attach(window, "load", function() {
		self.directory = document.getElementById(args.nodeId);
		if (self.directory == null) {
			alert("Error 534344.001: Can't initiate ShopCompactDirectoryHelper for node with id '" + args.nodeId + "', node does not exist!");
			return false;
		};
		self.replicate(args.replicate||3);
		self.startPosition(args.replicate||3);
		var mouseMoveEvent = Events.attach(self.directory, "mousemove", function(e) {
			window.internetexplorereventcancelationbugfix = true;
			return self.mouseOver(e||event, self);
		});
		var killEvent = Events.attach(document.body||document.documentElement, "mousemove", function(e) {
			if (!window.internetexplorereventcancelationbugfix) self.stop();
		});
		var cleanup = Events.attach(window, "unload", function() {
			Events.detach(mouseMoveEvent);
			Events.detach(killEvent);
			Events.detach(cleanup);
		});
		Events.detach(init);
	});
}

ShopCompactDirectoryHelper.prototype = {
	/**
	 * This method replicates a certain amount of items to make the
	 * seemless wrap-around back to the start of the list.
	 * @private
	 */
	replicate:function(num) {
		var d = this.directory;
		var count = 0;
		//remove whitespace nodes
		while (count < d.childNodes.length) {
			var c = d.childNodes[count];
			if (c.nodeType != 1) {
				d.removeChild(c);
			} else count++;
		}
		var children = d.childNodes;
		if (children.length > (num + 1)) { //(num +1) because when there's 4 products, one is the current one and no scrolling will be needed...
			for (i=0,s=0; (i - s) < num; d.appendChild(children[i++].cloneNode(true))) {
				if (children[i].className.indexOf("current_true") >= 0) s++;
			}
		}
	},
	startPosition:function(num) {
		var d = this.directory;
		var children = d.childNodes;
		if (children.length > (num + 1)) { //(num +1) because when there's 4 products, one is the current one and no scrolling will be needed...
			for (i=num; i < children.length; ++i) { //Skipping the first node because if that's the instace of current_true we want to jump to its' clone
				if (children[i].className.indexOf("current_true") >= 0) this.scroll(children[i - 1].offsetLeft);
			}
		}
	},
	/**
	 * This code stops the directory's animation.
	 */
	stop:function() {
		if (this.timer != false) {
			window.clearInterval(this.timer);
			this.timer = this._forward = this._fastforward = this._reverse = this._fastreverse = false;
			if (this.reporter) this.reporter.nodeValue = "Killed the timer";
			return true;
		} return false;
	},
	/**
	 * This code starts the directory's animation.
	 * 
	 * @param {int} The amount of pixels to jump forward per interval.
	 * @private
	 */
	start:function(px) {
		this.stop();
		var self = this;
		this.timer = window.setInterval( function() {
			//if (self.reporter) self.reporter.nodeValue = "Scrolling at a speed of " + px;
			self.scroll(px);
		}, 50 );
		if (this.reporter) this.reporter.nodeValue = "Started the timer";
	},
	/**
	 * @private
	 */
	forward:function() {
		if (this._forward) return true;
		else {
			this.start(1);
			this._forward = true;
		}
	},
	/**
	 * @private
	 */
	fastforward:function() {
		if (this._fastforward) return true;
		else {
			this.start(5);
			this._fastforward = true;
		}
	},
	/**
	 * @private
	 */
	reverse:function() {
		if (this._reverse) return true;
		else {
			this.start(-1);
			this._reverse = true;
		}
	},
	/**
	 * @private
	 */
	fastreverse:function() {
		if (this._fastreverse) return true;
		else {
			this.start(-5);
			this._fastreverse = true;
		}
	},
	/**
	 * This is the code-snippet use to scroll the directory.
	 * 
	 * @param {int} The amount of pixels to jump forward. 
	 * @private
	 */
	scroll:function(px) {
		window.internetexplorereventcancelationbugfix = false;
		var d = this.directory;
		var c = d.scrollLeft;
		d.scrollLeft=c + px;
		if (c == d.scrollLeft) d.scrollLeft = (c > 0)?0:(d.lastChild.offsetLeft + 1000);
	},
	/**
	 * Get the x and y position of the mouse, relative to the top-left
	 * corner of the directory.
	 * 
	 * @param {Event} The event object for the last mouse move.
	 * @private
	 */
	getPosition:function(e, rel) {
		var x = e.pageX||e.clientX;
		var y = e.pageY||e.clientY;
		var offsetX = rel.offsetLeft;
		var offsetY = rel.offsetTop;
		var relOffset = rel;
		while (relOffset = relOffset.offsetParent) {
			offsetX += relOffset.offsetLeft;
			offsetY += relOffset.offsetTop;
		}
		x -= offsetX;
		y -= offsetY;
		return {x:x,y:y};
	},
	/**
	 * A method to handle mouseover events on a directory html-construct.
	 * 
	 * @param {Event} The event object for the last mouse move.
	 * @param {ShopCompactDirectoryHelper} The helper object which is associated with this event/directory.
	 * @private
	 */
	mouseOver:function(e,helper) {
		var pos = this.getPosition(e, this.directory);
		var percent = Math.round(pos.x / this.directory.offsetWidth * 100);
		if (percent < this.regions.FR) { //The mouse moves in the leftmost 10 percent, fast-reverse speed
			helper.fastreverse();
			//if (this.reporter) this.reporter.nodeValue = "fr x=" + pos.x + ", y=" + pos.y + ", s=" + this.directory.scrollLeft;
		} else if (percent < this.regions.R) { //The mouse moves in the leftmost 33 percent, normal reverse speed
			helper.reverse();
			//if (this.reporter) this.reporter.nodeValue = "r x=" + pos.x + ", y=" + pos.y + ", s=" + this.directory.scrollLeft;
		} else if (percent > this.regions.FF) { //The mouse moves in the rightmost 10 percent, fast-forward speed
			helper.fastforward();
			//if (this.reporter) this.reporter.nodeValue = "ff x=" + pos.x + ", y=" + pos.y + ", s=" + this.directory.scrollLeft;
		} else if (percent > this.regions.F) { //The mouse moves in the rightmost 33 percent, normal forward speed
			helper.forward();
			//if (this.reporter) this.reporter.nodeValue = "f x=" + pos.x + ", y=" + pos.y + ", s=" + this.directory.scrollLeft;
		} else { //The mouse moves in the center 33 percent, don't move
			helper.stop();
			//if (this.reporter) this.reporter.nodeValue = "stop x=" + pos.x + ", y=" + pos.y + ", s=" + this.directory.scrollLeft;
		}
		return Events.cancel(e); //Need to cancel this event, otherwise the killEvent will stop it...
	},
	/**
	 * @private
	 */
	reporter:false//document.createElement("div").appendChild(document.createTextNode(""))
};


//jqZoom styles:

var options =
{
	zoomWidth: 273,
	zoomHeight: 250,	
	title: false,
	xOffset: 0,
	lens:false
}
var options2 =
{
	zoomWidth: 250,
	zoomHeight: 250,
	zoomType:'reverse'
}
var options3 =
{
	zoomWidth: 200,
	zoomHeight: 200,
	xOffset: 20,
	title: false,
	lens:false

}
var options4 =
{
	zoomWidth: 300,
	zoomHeight: 200,
	position : 'right',
	yOffset :-100,
	xOffset :100,
	title :false
}
var options5 =
{
	zoomWidth: 250,
	zoomHeight: 250,
	showEffect:'show',
	hideEffect:'fadeout',
	fadeoutSpeed: 'slow',
	title :false
}
var options6 =
{
	zoomWidth: 250,
	zoomHeight: 250
}

$j(document).ready(function(){
	
	$j(function() {
		// Banner highlight
		$j("img[src$=png], .podsvetka, .good-up, .inner-hover, .first, #enter").pngfix({ });

		   $j(".clickable").click(function(){
		   document.location = $j(this).attr('href');
		   })
		 
		   $j(".inner").mouseover(function(){
		    $j(this).css('cursor','pointer');
		    $j(this).prev('.podsvetka').css('visibility','visible');
		   }).mouseout(function(){
		    $j(this).css('cursor','pointer');
		    $j(this).prev('.podsvetka').css('visibility','hidden');
		   });
		
		//init zoom
		$j(".jqzoom").jqzoom(options);
		//$j(".jqzoom2").jqzoom(options2);   //da sistemare top/bottom
		//$j(".jqzoom3").jqzoom(options3);   //da sistemare top/bottom
		//$j(".jqzoom4").jqzoom(options4);  //da sistemare errore nella eliminazione zoom window
		//$j(".jqzoom5").jqzoom(options5);
		//$j(".jqzoom6").jqzoom(options6);   //da sistemare top/bottom
		   
		// init Flower of Time
		if (typeof 'runFT'=='function') {
			runFT();
		}   
	});	
	
	
		$j('.inner').click(function() {
			var thisLink = $j(this).find('td.join').find('a').attr('href');
			document.location = thisLink;
		});
		
		
	var rollOverBox = $j('div.actions-start');
	rollOverBox.mouseenter(function() {
		$j('div.box-popup').fadeIn(400);
	});
	rollOverBox.mouseleave(function() {
			$j('div.box-popup').fadeOut(400);
	});
	
	/*
	$j('a.button-enabled').click(function() {
		var formName = $j(this).parent().parent();
		var selectName = formName.find("select[name='select']");
		var optionSelect = selectName.find('option:selected');
	
		$j('body').append('<div id="id_err" style="display: none;width: 450px"><h1><i style="color: red">АХТУНГ!!!</i><br />Вы не выбрали товар!!! <p>Вы хотите сделать покупку?!?!</p></h1>Настоятельно рекомендуем Вам вернуться и выбрать товар!</div>')
		
		if (optionSelect.attr('value') == '') {
			Lightview.show('#id_err');
		} else {
			formName.submit();
		}
	});
	
	
	$j('a.btn').click(function() {
		var formName = $j(this).parent().parent().parent();
		formName.submit();
	})
	*/
	
	
	/* fade pix in shop/directory */
	
	$j('div.pix_holder').find('img').css('display', 'block');
	
	var box, obj, intervalID, startPix;
	var leave=true; // clear event
	
	$j('div.pix_holder').mouseenter(function() {
		if(leave) {
			box = $j(this).find('a'); // get parent
			pigs = box.html(); // save content
			
			whoIsNext(box); // use function
			leave=false; // hold event
			
			// set interval
			intervalID = window.setInterval(function(){
				whoIsNext(box); // use function
			}, 3000);
		}
		
	}).mouseleave(function() {
		leave=true; // clear event
		window.clearInterval(intervalID); // clear interval
		
		box.find('img').remove(); // remove content
		box.append(pigs); // paste save content
	});
	
	function whoIsNext(box) {
		obj = box.find('img:last-child'); // get object		
		// manipulation
		obj.fadeOut(500, function() {
			obj.prependTo(box).fadeIn('fast');
		});
	}
	
	//breadscrumbs
	$j('#breadscrumbs').find('td:last-child').find('a').attr('class', 'last');
	
	$j('#countrySelect').change(function () {
		var val = $j(this).attr('value');
		
		$j('select option:selected').each(function () {
			if(val != 'MO' && val != '') {
				$j('#hidden-areas').fadeIn().find('label.basket_zip').focus();
			} else {
				$j('#hidden-areas').fadeOut();
			}
		});
	});
	
	$j('div.invite-box').find('img').click(function() {
		$j(this).parent().find('div.signin-box').slideToggle("fast", function() {
			if($j(this).attr('style') == 'display: none;') {
				$j(this).find('div.loadinfo').fadeOut("fast");
			}
		});
	});
	
	// сейчас дополнительный кнтент (а-ля список друзей) показывается при клике 
	// на форму авторизации,
	// если я всё правильно понял надо повесить это на сабмит - при верной авторизации
	// немного переписав
	$j('div.invite-box').find('label').click(function() {
		$j(this).parent().find('div.loadinfo').fadeIn("slow");
	});
	
	// prizes 
	$j('div.contenttext').find('p:last-child').find('a.prizes_link').parent().css({ 
		backgroundImage : 'none',
		marginBottom : '-52px'
	});
	
	$j('div.contenttext').find('div.post-press-box:last-child').css({ 
		marginBottom : '-52px'
	});
	
	$j('div.contenttext').find('div.content-inner').click(function() {
		document.location = $j(this).find('a.b-link').attr('href');
	}).hover(function() {
		 $j(this).find('a.b-link').css({ textDecoration : 'underline' });
	}, function() {
		 $j(this).find('a.b-link').css({ textDecoration : 'none' });
	});
	
});