/* If the browser is IE6 and the page is not the home page redirect to home with the warning message */
if (	jQuery.browser.msie &&
	( parseInt(jQuery.browser.version.string.substring(0,1)) < 7 ) &&
	!(location.href.match("/home$")!=null && location.href.match("/home$")[0]=="/home")	) {

	location.href = "/home";
}

jQuery(document).ready(function() {
	
	// makes the account menu remains highlighted until the mouse
	jQuery('#account li a').hover(function(){ jQuery('#menu_account_post_it').addClass('account_over'); },function(){});
 	jQuery('#account').hover(function(){},function(){ jQuery('#menu_account_post_it').removeClass('account_over'); });
 	
	fixedElements = new Array(".logo", "#top-menu", "#menu-istitutional", "#search-box", "#menu_product", "#country_currency");
	fixedElementsTop = new Array(0, 0, 0, 0, 0, 0);
	absoluteElements = new Array("#box_window");
	absoluteElementsTop = new Array(0);
	for (var i=0; i<fixedElements.length; i++) {
		try { fixedElementsTop[i] = jQuery(fixedElements[i]).offset().top; }
		catch(err){ }
	}
	for (var i=0; i<absoluteElements.length; i++) {
		try { 
			absoluteElementsTop[i] = parseInt(jQuery(absoluteElements[i]).css("margin-top").replace("px","")); 
		} catch(err){ }
	}
	
	selectFooterItem();
	
	jQuery("#istitutional-menu-1").hover(function(){ istitutionalMenuRolloverClass(1); },function(){ istitutionalMenuRolloutClass(1); });
	jQuery("#istitutional-menu-2").hover(function(){ istitutionalMenuRolloverClass(2); },function(){ istitutionalMenuRolloutClass(2); });
	jQuery("#istitutional-menu-3").hover(function(){ istitutionalMenuRolloverClass(3); },function(){ istitutionalMenuRolloutClass(3); });

	jQuery("#item_products").hover(function(){ rolloverClass('products'); },function(){ rolloutClass('products'); });
	jQuery("#item_designers").hover(function(){ rolloverClass('designers'); },function(){ rolloutClass('designers'); });
	jQuery("#item_spaces").hover(function(){ rolloverClass('spaces'); },function(){ rolloutClass('spaces'); });
	jQuery("#item_specials").hover(function(){ rolloverClass('specials'); },function(){ rolloutClass('specials'); });
});

function istitutionalMenuRolloverClass(i) {
	jQuery("#istitutional-menu-"+i).addClass("over");
	jQuery("#menu-istitutional #mid-"+i).addClass("over");
}
function istitutionalMenuRolloutClass(i) {
	if (i != currentInstitutionalItem) {
		jQuery("#istitutional-menu-"+i).removeClass("over");
		jQuery("#menu-istitutional #mid-"+i).removeClass("over");
	}
}
	
function rolloverClass(i) {
	if (i != MainMenu.index1)
		jQuery(".menu_level1_container #mid-" + i).addClass("over");
}
function rolloutClass(i) {
	jQuery(".menu_level1_container #mid-" + i).removeClass("over");
}

function selectFooterItem()
{
	var page = document.getElementById("currentPage").value.replace(/\//g,'_');
	selectedLi= jQuery("#"+page);
	selectedLi.addClass('selectedFooterItem');
}

Liferay.Portlet.ready(
	// This function gets loaded after each and every portlet on the page.
	// portletId: the current portlet's id jQueryObj: the jQuery wrapped object of the current portlet
	function(portletId, jQueryObj) {
	}
);

jQuery(document).last(
	// This function gets loaded when everything, including the portlets, is on the page.
	function() {
	}
);

var fixedElements;
var absoluteElements;
var fixedElementsTop;
var absoluteElementsTop;
function fixedElementDown(elementSelector) {
	for (var i=0; i<fixedElements.length; i++) {
		try {
			jQuery(fixedElements[i]).css("top", (fixedElementsTop[i] + jQuery(elementSelector).height()) + "px");
		}
		catch(err) { }
	}
	for (var i=0; i<absoluteElements.length; i++) {
		try { jQuery(absoluteElements[i]).css("margin-top", (absoluteElementsTop[i] + jQuery(elementSelector).height()) + "px"); }
		catch(err) { }
	}
}
function fixedElementUp() {
	for (var i=0; i<fixedElements.length; i++) {
		try { jQuery(fixedElements[i]).css("top", fixedElementsTop[i] + "px"); }
		catch(err) { }
	}
	for (var i=0; i<absoluteElements.length; i++) {
		try { jQuery(absoluteElements[i]).css("margin-top", absoluteElementsTop[i] + "px"); }
		catch(err) { }
	}
}

/********************************************************************/
/*                       SLIDER                                     */
/********************************************************************/
function Slider(containerSelector, options) {
	var errors = "";

	var divElem = jQuery(containerSelector)[0];

	// default configuration properties
	var defaults = {
		//container
		containerWidth: jQuery(window).width(),
		containerHeight:500,
		autoresize:		true,
	
		//slider
		speed: 			800,
		offset:			0,
		urlSlide:		null,
		urlDetail:		null,
		prevSelector:	null,
		nextSelector:	null,
		withButton:		true,
		withBar:		false,

		//slide
		slideDivNumber: 1,
		slideWidth: 	320,
		fixedFirstSlide:false,
		firstSlideWidth:320,
		slideOpenWidth:	jQuery(window).width()*0.7,
		rightMargin:	0,
		leftMargin:		0,
		openDuration: 	300,
		closeDuration: 	200,
		onOpen:			null,
		onOpenComplete:	null,
		onClose:		null,
		onCloseComplete:null,
		onVisualize:	null,
		isOpen:			true,
		isGoToSlide:	true
	};

	options = jQuery.extend(defaults, options);
	divElem.isOneSlideOpen = false;

	var obj = jQuery(divElem);
	divElem.slider = obj.children(".strilloContainer");
	divElem.strilli =  divElem.slider.children(".strillo"+(options.fixedFirstSlide ? ":gt(0)" : ""));
	if(options.fixedFirstSlide)
		divElem.firstStrillo =  divElem.slider.children(".strillo:lt(1)");

	divElem.withBar = options.withBar;
	divElem.withButton = options.withButton && options.prevSelector != null && options.nextSelector != null;
	divElem.prevSelector = options.prevSelector;
	divElem.nextSelector = options.nextSelector;

	if(divElem.withBar) {
		jQuery(window).bind("scroll", function() { divElem.scrollElements(); });
	}

	if(divElem.withButton) {
		jQuery(divElem.prevSelector).css('visibility','hidden');
		jQuery(divElem.prevSelector).click(function() { divElem.slidePrev(); });
		jQuery(divElem.nextSelector).click(function() { divElem.slideNext(); });
	}

	divElem.widthWindow = jQuery(window).width();
	divElem.urlSlide = options.urlSlide;
	divElem.urlDetail = options.urlDetail;
	divElem.w = options.slideWidth + options.rightMargin + options.leftMargin;
	divElem.fixedFirstSlide = options.fixedFirstSlide;
	divElem.firstW = options.fixedFirstSlide ? options.firstSlideWidth + options.rightMargin + options.leftMargin : 0;
	var miniWidth = (divElem.strilli.size() * divElem.w) + divElem.firstW + options.offset;
	divElem.containerWidth = options.containerWidth > miniWidth ? miniWidth : options.containerWidth;
	divElem.percentWidth = divElem.containerWidth / divElem.widthWindow;
	
	divElem.containerHeigth = options.containerHeight;
	divElem.s = divElem.strilli.size();
	divElem.t = 0;
	divElem.slideWidth = options.slideWidth;
	divElem.slideOpenWidth = options.slideOpenWidth;
	divElem.ns = (divElem.containerWidth - options.offset - divElem.firstW) / divElem.w;
	divElem.h = options.containerHeight;
	divElem.ts = divElem.s - divElem.ns;

	divElem.openDuration = function() {
		return options.openDuration;
	};

	divElem.openWidth = function() {
		this.setSliderWidth(this.sliderWidth+this.slideOpenWidth-this.slideWidth);
		return this.slideOpenWidth;
	};

	divElem.openHeight = function() {
		return this.h;
	};

	divElem.closeDuration = function() {
		return options.closeDuration;
	};

	divElem.closeWidth = function() {
		return this.slideWidth;
	};

	divElem.closeHeight = function() {
		return this.h;
	};

	divElem.list = Array();
	divElem.current = null;
	
	obj.width(divElem.containerWidth);
	obj.height(divElem.containerHeight);
	obj.css({overflow: (divElem.withBar ? "" : "hidden")});

	divElem.slider.css({marginLeft: options.offset});
	divElem.strilli.height(divElem.h);
	divElem.strilli.width(options.slideWidth);
	divElem.strilli.css({marginRight:options.rightMargin, marginLeft:options.leftMargin, float: "left"});

	if(options.fixedFirstSlide) {
		divElem.t = -1;
		divElem.firstStrillo.height(divElem.h);
		divElem.firstStrillo.width(options.firstSlideWidth);
		divElem.firstStrillo.css({marginRight:options.rightMargin, marginLeft:options.leftMargin, float: "left"});
	}

	divElem.slideVisualizer = function(ns) {
		if(ns == undefined)
			ns = this.ns;

		for(var i=Math.ceil(this.t);i<this.s && i<=(this.t+ns); i++) {
			if(i<0)
				continue;
			this.list[i].slideVisualize();
		}
	};
	
	divElem.scrollElements = function() {
		var p = jQuery(window).scrollLeft();
		var ns = this.containerWidth / this.w;
		this.t = p<(options.offset*(this.withBar ? 0 : 1) + this.firstW) ? 0 : (p - options.offset*(this.withBar ? 0 : 1) - this.firstW) / this.w*(this.withBar ? 1 : -1);
		this.slideVisualizer(ns);
	};

	divElem.resizeElements = function() {
		divElem.widthWindow = jQuery(window).width();
		this.containerWidth = this.widthWindow * this.percentWidth;
		jQuery(this).width(this.containerWidth);
		this.ns = (this.containerWidth - options.offset) / this.w;
		this.slideVisualizer();
	};

	divElem.animate = function(ts, index, isOpen) {
		if(ts == undefined)
			ts = this.ts;

		this.t = (this.t>=ts) ? ts : ((this.t<=0) ? 0 : this.t);
		this.slideVisualizer();

		var p = this.t*this.w*(this.withBar ? 1 : -1)+options.offset*(this.withBar ? 0 : 1)+this.firstW;
		var maximumP = ((this.s*this.w + this.firstW - this.widthWindow)+options.offset);

		if(p > maximumP) {
			this.setSliderWidth(this.s*this.w + this.firstW + p - maximumP);
		}

		if(this.withBar) {
			jQuery('html,body').animate({ scrollLeft: p }, "slow");
		} else {
			this.slider.animate( { marginLeft: p }, options.speed);
		}
		
		if(isOpen) {
			this.list[index].slideOpen();
		}
	};

	divElem.addSlide = function(divElem) {
		divElem.slideOnOpen 			= options.onOpen;
		divElem.slideOnOpenComplete		= options.onOpenComplete;
		divElem.slideOnClose			= options.onClose;
		divElem.slideOnCloseComplete	= options.onCloseComplete;
		divElem.slideOnVisualize		= options.onVisualize;
		divElem.loading					= false;

		divElem.slideStatus = 'closed'; // 'closed', 'opened', 'opening', 'closing'.
		divElem.clickCloseButton = false; 

		divElem.slideVisualize = function() {
			if (typeof(this.slideOnVisualize) == 'function' && !this.loading) {
				this.slideOnVisualize();
				divElem.loading = true;
			}
		};

		divElem.slideOpen = function() {
			var proceed = true;

			if (typeof(this.slideOnOpen) == 'function' && this.container.current != this)
				proceed = divElem.slideOnOpen();

			if (proceed && this.container.current != null && this.container.current != this)
				proceed = this.container.current.slideClose();

			if (proceed && this.slideStatus == 'closed') {
				this.container.current = divElem;
				this.slideStatus = 'opening';
		
				jQuery(this).animate(
					{
						width: this.container.openWidth() + 'px',
						height: this.container.openHeight() + 'px'
					},
					this.container.openDuration(),
					'linear',
					function() {
						this.slideStatus = 'opened';
						if (typeof(this.slideOnOpenComplete) == 'function')
							this.slideOnOpenComplete();
					}
				);
				
				return true;
			}
			return false;
		};

		var myThis;
		divElem.slideClose = function() {
			var proceed = true;

			if (typeof(this.slideOnClose) == 'function')
				proceed = this.slideOnClose();

			if (proceed && this.slideStatus == 'opened') {
				if (this.container.current == divElem)
					this.container.current = null;

				this.slideStatus = 'closing';
				if (this.container.isOneSlideOpen) {
					this.container.restoreSliderWidth();
				}
				jQuery(this).animate(
					{
						width: this.container.closeWidth() + 'px',
						height: this.container.closeHeight() + 'px'
					},
					this.container.closeDuration(),
					'linear',
					function() {
						if(!this.container.isOneSlideOpen) {
							this.container.restoreSliderWidth();
						}
						this.slideStatus = 'closed';
						if (typeof(this.slideOnCloseComplete) == 'function') {
							this.slideOnCloseComplete();
						}
					}
				);

				return true;
			}

			return false;
		};

		divElem.setWidth = function(width) {
	        if(width!=null) {
	                this.container.setSliderWidth(this.container.sliderWidth + (width - jQuery(this).width()));
	                jQuery(this).width(width);
	        }
	    };
 
		divElem.container = this;
		this.list.push(divElem);
		return divElem;
	};

	divElem.gotoSlide = function(index, ts, isOpen) {
		if(ts == undefined)
			ts = this.ts;

		if(isOpen == undefined)
			isOpen = options.isOpen;

		if(this.current == this.list[index]) {
			return;			
		}

		if(this.list[index].clickCloseButton) {
			this.list[index].clickCloseButton = false;
			return;			
		}

		if(this.current!=null) {
			this.current.slideClose();
		}

		this.t = index;
		this.checkingButton(ts);
		this.animate(ts, index, isOpen);
	};

	divElem.slideNext = function() {
		if(this.withBar)
			this.gotoSlide(Math.ceil(this.t + options.slideDivNumber), this.s-1, false);			
		else
			this.gotoSlide(this.t + options.slideDivNumber, this.ts, false);
	};

	divElem.slidePrev = function() {
		if(this.withBar) {
			if(this.t - options.slideDivNumber < 0) {
				this.t = (this.fixedFirstSlide ? -1 : 0);				
				jQuery(window).scrollLeft(0);
				this.checkingButton();
				if(this.current!=null) {
					this.current.slideClose();
				}
			} else {		
				this.gotoSlide(Math.ceil(this.t - options.slideDivNumber), this.s-1, false);
			}
		} else
			this.gotoSlide(this.t - options.slideDivNumber < 0 ? 0 : this.t - options.slideDivNumber, this.ts, false);
	};

	divElem.checkingButton = function(ts) {
		if(ts == undefined)
			ts = this.ts;

		if(this.withButton) {
			if(this.t<=ts) {
				jQuery(this.nextSelector).css('visibility','visible');
			}
			if (this.t>(this.fixedFirstSlide ? -1 : 0)) {
				jQuery(this.prevSelector).css('visibility','visible');
			}
			if(this.t>=ts) {
				jQuery(this.nextSelector).css('visibility','hidden');
			} 
			if(this.t<=(this.fixedFirstSlide ? -1 : 0)) {
				jQuery(this.prevSelector).css('visibility','hidden');
			}
		}
	};

	divElem.closeCurrentSlide = function() {
		if(this.current==null)
			return;

		this.current.slideClose();
	};

	divElem.setSliderWidth = function(sliderWidth, restore) {
		this.sliderWidth = sliderWidth;
		this.slider.width(sliderWidth);
	};

	divElem.restoreSliderWidth = function() {
		this.setSliderWidth(this.s*this.w + this.firstW);
	};

	if(options.autoresize) {
		jQuery(window).bind("resize", function() { divElem.resizeElements(); });
	}

	divElem.strilli.each(
		function(index){
			this.parentNode.parentNode.addSlide(this);
			
			if(index <= this.container.ns) {
				this.slideVisualize();
			}

			if(options.isGoToSlide) {
				this.index = index;
				jQuery(this).click(function(){ this.container.gotoSlide(index, this.container.s -1); });
			}
	});

	divElem.setSliderWidth(divElem.s*divElem.w + divElem.firstW);
	divElem.checkingButton();
	return divElem;
}

/********************************************************************/
/*                 JQUERY.MOUSEWHEEL                                */
/********************************************************************/

(function($) {

	var types = ['DOMMouseScroll', 'mousewheel'];

	$.event.special.mousewheel = {
		setup: function() {
			if ( this.addEventListener )
				for ( var i=types.length; i; )
					this.addEventListener( types[--i], handler, false );
			else
				this.onmousewheel = handler;
		},
		
		teardown: function() {
			if ( this.removeEventListener )
				for ( var i=types.length; i; )
					this.removeEventListener( types[--i], handler, false );
			else
				this.onmousewheel = null;
		}
	};

	$.fn.extend({
		mousewheel: function(fn) {
			return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
		},
		
		unmousewheel: function(fn) {
			return this.unbind("mousewheel", fn);
		}
	});


	function handler(event) {
		var args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true;
		
		event = $.event.fix(event || window.event);
		event.type = "mousewheel";
		
		if ( event.wheelDelta ) delta = event.wheelDelta/120;
		if ( event.detail     ) delta = -event.detail/3;
		
		// Add events and delta to the front of the arguments
		args.unshift(event, delta);

		return $.event.handle.apply(this, args);
	}

	})(jQuery);

/********************************************************************/
/*                 JSCROLLER                                        */
/********************************************************************/

jScroller = function() {};

jScroller.defaultOptions = {
	scrollBarWidth: 7,
	scrollSpeed: 7,
	scrollSpeedMode: 'px', // 'px' - how many pixels the scrollbar will move, '%' - how much of the scrollbar length will move
	scrollBarClass: 'jScroller_scrollBarClass',
	scrollerClass: 'jScroller_scrollerClass',
	enableDragEvent: true,
	enableWheelEvent: true
};

jScroller.create = function(elemSelector, options) {
	options = jQuery.extend(jScroller.defaultOptions, options);
	var elems = jQuery(elemSelector);
	elems.each(function() {
		this.scrollBarY = 0;
		
		this.refresh = function(sizeChanged) {
			var jThis = jQuery(this);
			if (sizeChanged) {
				this.jContent.width(jThis.width() - options.scrollBarWidth);
				this._height = jThis.height();
				this._contentHeight = this.jContent.height();
				this._heightFactor = Math.min(this._height / this._contentHeight, 1);
				this._scrollBarHeight = this._heightFactor * this._height;

				if (this._heightFactor == 1)
					this.jContent.width(jThis.width());
				
				this.jScroller.css({height: this._height + 'px'});
				this.scroller.jScrollBar.css({height: this._scrollBarHeight + 'px'});
			}
			
			if (this._heightFactor < 1) {
				var scrollDelta = this._height - this._scrollBarHeight;
				if (this.scrollBarY < 0)
					this.scrollBarY = 0;
				else if (this.scrollBarY > scrollDelta)
					this.scrollBarY = scrollDelta;
					
				this.scrollTop = (this.scrollBarY / scrollDelta) * (this._contentHeight - this._height);
				this.jScroller.css({top: this.scrollTop + 'px', display: '', visibility: 'visible'});
				this.scroller.jScrollBar.css({top: this.scrollBarY + 'px'});
			} else {
				this.scrollTop = 0;
				this.jScroller.css({display: 'none', visibility: 'hidden'});
			}
			this.jContent.css({top: this.scrollTop + 'px'});
		};
		
		this.scroll = function(ticks) {
			if (options.scrollSpeedMode == 'px')
				this.scrollBarY = this.scrollBarY + ticks;
			else if (options.scrollSpeedMode == '%')
				this.scrollBarY = this.scrollBarY + (ticks * 0.01 * this._scrollBarHeight);
			this.refresh();
		};
		
		var jThis = jQuery(this);
		jThis.css({overflow: 'hidden'});
		jThis.html(
			'<div id="' + this.id + '_content" style="float: left;">' + jThis.html() + '</div>' +
			'<div id="' + this.id + '_scroller" class="' + options.scrollerClass + '" style="position: relative; width:' + options.scrollBarWidth + 'px; float: left;">' +
			'    <div id="' + this.id + '_scrollbar" class="' + options.scrollBarClass + '" style="position: relative; width:' + options.scrollBarWidth + 'px; top: ' + this.scrollBarY + 'px; "></div>' +
			'</div>');
			
		this.jContent = jQuery('#' + this.id + '_content', this);
		if (this.jContent.size() > 0) {
			this.jContent[0].parent = this;
			this.content = this.jContent[0];
		}
		this.jScroller = jQuery('#' + this.id + '_scroller', this);
		if (this.jScroller.size() > 0) {
			this.jScroller[0].parent = this;
			this.scroller = this.jScroller[0];
			this.scroller.jScrollBar = jQuery('#' + this.id + '_scrollbar', this.scroller);
			if (this.scroller.jScrollBar.size() > 0) {
				this.scroller.jScrollBar[0].parent = this.jScroller[0];
				this.jScroller[0].scrollBar = this.scroller.jScrollBar[0];
			}
		}
		
		this.refresh(true);
		
		var myThis;
		if (options.enableDragEvent) {
			this.scroller.jScrollBar.bind('mousedown', function(e) {
				myThis = this;
				if (e.preventDefault)
					e.preventDefault();
				this.parent.parent.clickY = e.pageY;
				this.parent.parent.clickScrollBarY = this.parent.parent.scrollBarY;
				jQuery('html').bind('mousemove', function(e) {
					myThis.parent.parent.scrollBarY = myThis.parent.parent.clickScrollBarY + (e.pageY - myThis.parent.parent.clickY);
					myThis.parent.parent.refresh();
				});
				jQuery('html').bind('mouseup', function(e) {
					jQuery('html').unbind('mousemove');
				});
			});
			this.jScroller.bind('mouseup', function(e) {
				jQuery(this.scrollBar).unbind('mousemove');
				jQuery(this).unbind('mousemove');
			});
		}
		
		if (options.enableWheelEvent) {	
			jThis.mousewheel(function(e, delta) {
				this.scroll(-delta * options.scrollSpeed);
			});
		}
	});
	
	return elems;
};

/********************************************************************/
/*                 JTABBER                                          */
/********************************************************************/
jTabber = function() {};

jTabber.defaultOptions = {
	openInterval: 1000,
	closeInterval: 1000,
	onClick: null,
	beforeOpen: null,
	onOpen: null,
	beforeClose: null,
	onClose: null
};

jTabber.create = function(tabberQuery, headQuery, bodyQuery, options) {
	var options = jQuery.extend(jTabber.defaultOptions, options);
	var jTabbers = jQuery(tabberQuery);
	jTabbers.each(function() {
		var jThis = jQuery(this);
		this.jHeaders = jQuery(headQuery, this);
		this.jBodies = jQuery(bodyQuery, this);
		this.tabCount = Math.min(this.jHeaders.size(), this.jBodies.size());
		this.currentTab = -1;
		
		this.jHeaders.click(function(event) {
			if (options.onClick != null)
				options.onClick(jQuery.extend(event, {tab: this}));
			if (this.tabBody.tabState == 'closed') {
				if (this.parent.currentTab != -1)
					this.parent.jHeaders[this.parent.currentTab].close();
				this.parent.currentTab = this.tabIndex;
				this.open();
			} else if (this.tabBody.tabState == 'opened') {
				this.parent.currentTab = -1;
				this.close();
			}
		});
		
		this.jBodies.css({overflow: 'hidden'});
		
		for (var i = 0; i < this.tabCount; i++) {
			var tmp = this.jBodies[i];
			tmp.tabHeight = jQuery(this.jBodies[i]).height();
			tmp.tabState = 'closed';
			jQuery(tmp).css({height: '0px'});
			var tmp2 = this.jHeaders[i];
			tmp2.tabBody = tmp;
			tmp.tabHead = tmp2;
			tmp2.tabIndex = i;
			tmp2.parent = this;
			
			tmp2.open = function() {
				var tmp = jQuery(this.tabBody);
				this.tabBody.tabState = 'opening';
				if (options.beforeOpen != null)
					options.beforeOpen(this.tabIndex);
				tmp.animate({height: this.tabBody.tabHeight + 'px'}, options.openInterval, function() {
					this.tabState = 'opened';
					tmp.css({height: ''});
					this.tabHeight = tmp.height();
					if (options.resetDimensions)
						tmp.css({height: this.tabHeight + 'px'});
					if (options.onOpen != null)
						options.onOpen(this.tabHead.tabIndex);
					jQuery(this.tabHead).addClass("title-blue");
				});
			};
			tmp2.close = function() {
				var tmp = jQuery(this.tabBody);
				this.tabBody.tabState = 'closing';
				if (options.beforeClose != null)
					options.beforeClose(this.tabIndex);
				tmp.animate({height: '0px'}, options.closeInterval, function() {
					this.tabState = 'closed';
					if (options.onClose != null)
						options.onClose(this.tabHead.tabIndex);
					jQuery(this.tabHead).removeClass("title-blue");
				});
			};
		}
	});
	
	return jTabbers;
};

currentInstitutionalItem = -1;
setCurrentInstitutionalItem = function(i) {
	currentInstitutionalItem = i;
	jQuery("#istitutional-menu-"+i).addClass("over");
	jQuery("#menu-istitutional #mid-"+i).addClass("over");
};

jPrint=function(el) {
	var iframe = document.getElementById('printIFrame');
	var doc = null;
	if (iframe == null) {
		iframe = document.createElement('IFRAME');
		jQuery(iframe).attr('style','position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
		jQuery(iframe).attr('id','printIFrame');
		document.body.appendChild(iframe);
	}
	doc=iframe.contentWindow.document;
	var links=window.document.getElementsByTagName('link');
	for(var i=0;i<links.length;i++)
		if(links[i].rel.toLowerCase()=='stylesheet')
			doc.write('<link type="text/css" rel="stylesheet" href="'+links[i].href+'"></link>');
	doc.write('<div class="'+jQuery(el).attr("class")+'">'+jQuery(el).html()+'</div>');
	jQuery('body', doc).attr('style', 'background: #FFFFFF;');
	setTimeout(function() { printNow(doc,iframe); }, 100);
};
function printNow(doc, iframe) {
	doc.close();
	iframe.contentWindow.focus();
	iframe.contentWindow.print();
}

// TOPMENU
function TopMenu() {
	this.list = new Array();
	this.openLink = null;
	this.openMiddle = null;
	this.permanentActive = "#top-menu-4";
};

TopMenu.istance = null;

TopMenu.getInstance = function() {
	if (TopMenu.instance == null)
		TopMenu.instance = new TopMenu();
	return TopMenu.instance;
};


TopMenu.prototype.add = function (link, middle, div, closeButton, funz) {
	var instance = this;
	this.list[link] = {div: div, closeButton: closeButton};
	var jLink = jQuery(link);
	jLink.hover(function(){ instance.rolloverClass(link, middle); }, function(){ instance.rolloutClass(link, middle); });
	
	jLink.click(function() {
		if ( (instance.openLink != link) && (link != instance.permanentActive) ) {
			instance.hideOpenLink(link);
			jQuery(div).show();

			fixedElementDown(div);

			jQuery(link).addClass("over");
			jQuery(middle).addClass("over");
			jQuery(link + ' > .top-menu-active').addClass("over");
			instance.openLink = link;
			instance.openMiddle = middle;
		} else
			instance.hideOpenLink(link, middle);
	});

	if(closeButton != undefined)
		jQuery(closeButton).click(function() {
			instance.hideOpenLink(link, middle);
		});
	
	jQuery(div).hide();

	if(funz != undefined)
		funz();
};

TopMenu.prototype.hideOpenLink = function(link, middle) {
	if(this.openLink != null) {
		jQuery(this.list[this.openLink].div).hide();
		fixedElementUp();
		jQuery(this.openLink).removeClass("over");
		jQuery(this.openMiddle).removeClass("over");
		jQuery(this.openLink + ' > .top-menu-active').removeClass("over");
		this.openLink = null;
		this.openMiddle = null;
	}	
};

TopMenu.prototype.rolloverClass = function(link, middle) {
	jQuery(link).addClass("over");
	jQuery(middle).addClass("over");
};

TopMenu.prototype.rolloutClass = function(link, middle) {
	if ( (link != this.openLink) && (link != this.permanentActive) ) {
		jQuery(link).removeClass("over");
		jQuery(middle).removeClass("over");
	}
};

// Istitutional invokedy by why and who
function istitutionalBoxDxFixed() {
	var jInstRight = jQuery(".istitutional_content .right");
	jInstRight.css("width", jQuery(window).width() - jQuery(".istitutional_content .left").width() - (parseInt(jQuery("#box_window").css("left")) * 2) - parseInt(jInstRight.css("margin-left")) );
}

/********************************************************************/
/*                 OFFSET                                           */
/********************************************************************/

//2009-03-20
(function($){

$.fn.extend({

	/**
	 * Stores the original version of offset(), so that we don't lose it
	 */
	_offset : $.fn.offset,
	
	/**
	 * Set or get the specific left and top position of the matched
	 * elements, relative the the browser window by calling setXY
	 * @param {Object} newOffset
	 */
	offset : function(newOffset){
	    return !newOffset ? this._offset() : this.each(function(){
			var el = this;
			
			var hide = false;
			
			if($(el).css('display')=='none'){
				hide = true;
				$(el).show();
			};
			
			var style_pos = $(el).css('position');
			
			// default to relative
			if (style_pos == 'static') {
				$(el).css('position','relative');
				style_pos = 'relative';
			};
			
			var offset = $(el).offset();
			
			if (offset){
				var delta = {
					left : parseInt($(el).css('left'), 10),
					top: parseInt($(el).css('top'), 10)
				};
				
				// in case of 'auto'
				if (isNaN(delta.left)) 
					delta.left = (style_pos == 'relative') ? 0 : el.offsetLeft;
				if (isNaN(delta.top))
					delta.top = (style_pos == 'relative') ? 0 : el.offsetTop;
				
				if (newOffset.left || newOffset.left===0)
					$(el).css('left',newOffset.left - offset.left + delta.left + 'px');
			
				if (newOffset.top || newOffset.top===0)
					$(el).css('top',newOffset.top - offset.top + delta.top + 'px');
			};
			if(hide) $(el).hide();
		});
	}

});

})(jQuery);

// CART
function cart_StepNumber(number) {
	var array = jQuery("#menu_checkout .ui-tabs li");
	for(var i=0; i<4; i++) {
		if(i <= number) {
			jQuery(array[i]).css('background', 'url("/html/themes/didisegno/images/didisegno/numeri/attivi/'+(i+1)+'_SezioniMancanti.png") no-repeat 15px 10px #113854');
			jQuery(array[i]).css('border-top', '1px solid #16537E');
			jQuery(array[i]).children("a").css('color','#FFFFFF');
		} else {
			jQuery(array[i]).css('background', 'url("/html/themes/didisegno/images/didisegno/numeri/disattivi/'+(i+1)+'_SezioniMancanti.png") no-repeat 15px 10px #031421');
			jQuery(array[i]).css('border-top', '1px solid #001D32');
			jQuery(array[i]).children("a").css('color','#4C4C4C');
		}
	}
}

// WHERE
function whereInit() {
    jTabber.create('#where', '.where_head', '.where_body_content', {resetDimensions: true,
        beforeClose: function(i) {
            jQuery('#where_map_' + (i+1) + ' iframe').hide();
            jQuery('#where_image_prev_' + (i+1)).hide();
            jQuery('#where_image_next_' + (i+1)).hide();
            jQuery('#where_image_' + (i+1)).hide();
        },
        onOpen: function(i) {
    		jQuery('#where_body_' + (i+1) + ' #where_map iframe').show();
        	jQuery('#where_body_' + (i+1) + ' #where_image_prev').show();
        	jQuery('#where_body_' + (i+1) + ' #where_image_next').show();
        	jQuery('#where_body_' + (i+1) + ' #where_image').show();
        },
        beforeOpen: function(i) {
            jQuery('#where_head_' + (i+1)).addClass('open');
        },
        onClose: function(i) {
            jQuery('#where_head_' + (i+1)).removeClass('open');
        },
		openInterval: 500,
		closeInterval: 500
    });
    imageCount1 = parseInt(jQuery('#where_body_1 #Image_count').val());
    imageCount2 = parseInt(jQuery('#where_body_2 #Image_count').val());
    currentImage1 = 0;
    currentImage2 = 0;
    imageWidth = jQuery('.where_image').width();
    whereImageAnimating = false;

    jQuery('#where_body_1 #where_image_prev').click(function() {if (!whereImageAnimating) whereImageMove(1, -1);});
    jQuery('#where_body_1 #where_image_next').click(function() {if (!whereImageAnimating) whereImageMove(1, 1);});
    jQuery('#where_body_2 #where_image_prev').click(function() {if (!whereImageAnimating) whereImageMove(2, -1);});
    jQuery('#where_body_2 #where_image_next').click(function() {if (!whereImageAnimating) whereImageMove(2, 1);});

}
whereImageMove = function(image, dir) {
    if (image == 1) {
        currentImage1 += dir;
        if (currentImage1 < 0)
            currentImage1 += imageCount1;
        if (currentImage1 >= imageCount1)
            currentImage1 -= imageCount1;
        whereImageAnimating = true;
        jQuery('#where_body_1 #where_image_container').animate({left: (-currentImage1 * imageWidth) + 'px'}, 100, function() {whereImageAnimating = false;});
    } else {
        currentImage2 += dir;
        if (currentImage2 < 0)
            currentImage2 += imageCount2;
        if (currentImage2 >= imageCount2)
            currentImage2 -= imageCount2;
        whereImageAnimating = true;
        jQuery('#where_body_2 #where_image_container').animate({left: (-currentImage2 * imageWidth) + 'px'}, 100, function() {whereImageAnimating = false;});
    }
};

// HORIZONTAL SCROLL BUTTON
HorizontalScrollButton = function() {
	var options;
};

HorizontalScrollButton.defaultOptions = {
	offset:		165,
	prevSelector:	null,
	nextSelector:	null
};

HorizontalScrollButton.create = function(options) {
	this.options = jQuery.extend(HorizontalScrollButton.defaultOptions, options);
	
	this.checkNecessaryScrollButton();
	jQuery(window).scroll(function () {
		HorizontalScrollButton.checkNecessaryScrollButton();
	});

	jQuery(options.nextSelector).click(function() {
		jQuery(options.nextSelector).hide();
		jQuery('html,body')
 			.animate(
				{ scrollLeft: (jQuery(window).scrollLeft() + options.offset) },
				"slow",
				function() { HorizontalScrollButton.checkNecessaryScrollButton(); } );
	});

	jQuery(options.prevSelector).click(function() {
		jQuery(options.prevSelector).hide();
		jQuery('html,body')
 			.animate(
				{ scrollLeft: (jQuery(window).scrollLeft() - options.offset) },
				"slow",
				function() { HorizontalScrollButton.checkNecessaryScrollButton(); } );
	});
	return this;
};
HorizontalScrollButton.checkNecessaryScrollButton = function() {
	var jWindow = jQuery(window);
	if (jWindow.scrollLeft() > 0)
		jQuery(this.options.prevSelector).show();
	else
		jQuery(this.options.prevSelector).hide();
	var jStrCont = jQuery(".strilloContainer");
	var showNext = (jWindow.scrollLeft() + jWindow.width() - jStrCont.width() - jStrCont.offset().left ) >= 0;
	if (showNext)
		jQuery(this.options.nextSelector).hide();
	else
		jQuery(this.options.nextSelector).show();
};