/**
 * menu switcher
 */
var SubNav = {
	navLeft: null,
	navRight: null,
	count: null,
	countUl: null,
	index: 0,
	duration: 250,

	init: function()
	{
		jQuery.noConflict();
		SubNav.countUl = jQuery(".subNav ul").find("ul").length;
		SubNav.count = jQuery(".subNav ul li").length;
		jQuery(".subNav ul").addClass('nav-root');
		jQuery(".subNav ul ul").removeClass('nav-root');

		SubNav.setNewHeight();
		SubNav.setNavPoints();
		SubNav.move(SubNav.countUl-1);

		if(jQuery('.pointernav a').length <= 1) {
			jQuery('.pointernav').addClass('inv');
			jQuery('.subNav').addClass('inv');
		}
	},

	setNewHeight: function()
	{
		var subNavUl = jQuery('.subNav ul ul'),
			l		 = subNavUl.length,
			newHeight= 0;

		if(subNavUl.length == 0)
			return;

		while(--l) {

			var a = subNavUl[l].clientHeight,
				b = subNavUl[l-1].clientHeight;

			newHeight = a;
			if(a < b)
				newHeight = b;
		}

		jQuery('.subNav').css('height', newHeight);
	},

	setNavPoints: function()
	{
		var navArray = [];

		navArray.push('<div class="pointernav">');
		for( var i = 0, l = SubNav.countUl; i<l;++i )
			navArray.push('<a id="navpoint_' + i + '" href="javascript:void(0)" class="navpoint" onclick="SubNav.move(SubNav.checkMove(this));"></a>');

		navArray.push('<div class="clear"></div></div>');

		jQuery(navArray.join('')).insertBefore('.subNav');
		jQuery('#leftNav .navpoint:last').addClass('active');
	},

	checkMove: function(check) 
	{
		var activePoint = jQuery('#leftNav .pointernav a.active'),
			numberActive = activePoint[0].id.split('_')[1],
			numberNew = check.id.split('_')[1],
			naviNumber = '';

		if(numberActive > numberNew)
			naviNumber = '-' + Math.round(numberActive-numberNew);
		else
			naviNumber = Math.round(numberNew-numberActive);

		activePoint.removeClass('active');
		jQuery('#' + check.id).addClass('active');
		return parseInt(naviNumber);
	},

	move: function( dir )
	{
		if(dir >= 1) {
			SubNav.moveRight(dir);
		}else if(dir <= -1) {
			SubNav.moveLeft(dir);
		}
	},

	moveRight: function(index)
	{
		if(index != undefined)
			setMargin = Math.round(index * 205);
		else
			setMargin = 205;
		jQuery(".subNav ul.nav-root").animate({
	        marginLeft: "-=" + setMargin + "px"
	    }, SubNav.duration );
	},

	moveLeft: function(index)
	{
		if(index != undefined)
			setMargin = Math.round(index * -205);
		else
			setMargin = 205;
		jQuery(".subNav ul.nav-root").animate({
	        marginLeft: "+=" + setMargin + "px"
	    }, SubNav.duration );
	}	
};

var NewsSlider = {

	navLeft: null,
	navRight: null,
	count: null,
	index: 0,
	duration: 250,
	fontSize: 12,
	infoEl: null,
	intervall:null,

	init: function()
	{	
		NewsSlider.count = jQuery(".news-slider-items ul li").length;
		NewsSlider.infoEl = jQuery(".news-slider-navInfo span");
		NewsSlider.navLeft = jQuery(".news-slider-nav .navLeft");
		NewsSlider.navRight = jQuery(".news-slider-nav .navRight");

		var width = NewsSlider.count * 13;
		NewsSlider.infoEl.css({'width':width + 'px'});	
		NewsSlider.infoEl.parent().show();

		NewsSlider.intervall = window.setInterval( 'NewsSlider.move( 1 )', 5000 );		
	},

	move: function( dir )
	{		
		if( NewsSlider.index + 1 == NewsSlider.count) {
			NewsSlider.returnToBegin();
			return;
		}

		if( dir == 1 && ( NewsSlider.index + 1 ) < NewsSlider.count )
			NewsSlider.moveRight();

		if( dir == -1 && NewsSlider.index > 0 )
			NewsSlider.moveLeft();
	},

	moveRight: function()
	{
		NewsSlider.navLeft.removeClass( 'navLeft_inactive' );

		jQuery(".news-slider-items ul").animate({
	        marginLeft: "-=303px"
	    }, NewsSlider.duration );

		NewsSlider.index++;		
		NewsSlider.calcInfoBG( 1 );

		if( ( NewsSlider.index + 1 ) ==  NewsSlider.count )
			NewsSlider.navRight.addClass( 'navRight_inactive' );
		else
			NewsSlider.navRight.removeClass( 'navRight_inactive' );
			
	},

	moveLeft: function()
	{
		NewsSlider.navRight.removeClass( 'navRight_inactive' );

		jQuery(".news-slider-items ul").animate({
	        marginLeft: "+=303px"
	    }, NewsSlider.duration );

		NewsSlider.index--;
		NewsSlider.calcInfoBG( -1 );
		
		if( NewsSlider.index == 0 )
			NewsSlider.navLeft.addClass( 'navLeft_inactive' );
		else
			NewsSlider.navLeft.removeClass( 'navLeft_inactive' );
	},
	
	returnToBegin: function() {
		NewsSlider.index = 0;
		var countItems = jQuery(".news-slider-items ul li").length;
		jQuery(".news-slider-items ul").animate({
	        marginLeft: "+=" + Math.round((countItems - 1) * 303) + 'px'
	    }, NewsSlider.duration );
		
		NewsSlider.navRight.removeClass( 'navRight_inactive' );
		NewsSlider.navLeft.addClass( 'navLeft_inactive' );
		
		NewsSlider.calcInfoBG( -2 );
	},

	calcInfoBG: function( dir )
	{
		bgPos = 0;

		if( jQuery.browser.msie )
		{
			bgPos = NewsSlider.infoEl.css( 'background-position-x' );
		}
		else
		{
			bgPos = NewsSlider.infoEl.css( 'background-position' );
			bgPos = bgPos.split( ' ' )[ 0 ];			
		}
		
		if(dir == -2) {
			var length = jQuery(".news-slider-items ul li").length,
				bgPos = Number(bgPos.replace('px', ''));
			NewsSlider.infoEl.css({'background-position' : Math.round(bgPos - ((length - 1) * 14)) + 'px 0'});
			return;
		}

		bgPos = bgPos.replace( 'px', '' );
		bgPos = ( dir == -1 ) ? Number( bgPos ) - 14 : Number( bgPos ) + 14;
		NewsSlider.infoEl.css({'background-position' : bgPos + 'px 0'});
	}
};

/**
 * Change select into div-select
 */
var selector = {
	select: null,
	parentUid: null,
	currOptionField: null,

	init: function() {
		jQuery.noConflict();
		if(jQuery('form select').length == 0)
			return;

		var selectors = jQuery('select'),
			count = selectors.length,
			i = 0;

		while(count--) {
			this.select = selectors[i];
			this.changeSelect();
			this.onEvent();
			++i;
		};
	},

	onEvent: function() {
		jQuery('body').click(function(e) {
			var activeOption = jQuery(e.target);

			if(activeOption.hasClass('selectButton') && activeOption[0].nodeName == 'SPAN') {
				var siblingOption = activeOption.siblings('div.options'),
					activeOptionCheck = jQuery('div.selectParent div.options');

				if(activeOptionCheck.hasClass('active'))
					activeOptionCheck.removeClass('active');

				if(siblingOption.hasClass('active'))
					siblingOption.removeClass('active');
				else
					siblingOption.addClass('active');

			}else if(activeOption.parent('div').hasClass('options') && activeOption[0].nodeName == 'LABEL') {
				var input = activeOption.parent('div').prev('input');
				input[0].value = activeOption[0].textContent;
				activeOption.parent('div.options').removeClass('active');
			}else if(jQuery('div.selectParent div.options').hasClass('active')) {
				jQuery('div.selectParent div.options').removeClass('active');
			}
		});
	},

	changeSelect: function() {
		var options = this.select.options,
			oLength = options.length,
			newSelect = document.createElement('input'),
			newOptionsDiv = document.createElement('div'),
			newButton = document.createElement('span');

		newOptionsDiv.className = 'options';

		this.parentUid = jQuery('#' + this.select.id).parent()[0].id == undefined ? '' : jQuery('#' + this.select.id).parent()[0].id;

		if(this.parentUid == "") {
			var newParentDiv = document.createElement('div');
			newParentDiv.id = 'parentDiv_' + this.select.id.split('_')[1];

			jQuery(newParentDiv).css('position', 'relative');
			jQuery(newParentDiv).addClass('selectParent');
			jQuery(newParentDiv).insertBefore(this.select);
			jQuery(this.select).remove();
			newParentDiv.appendChild(this.select);

			this.parentUid = newParentDiv.id;
		}

		for(var i = 0, l = oLength; i < l; ++i) {
			var newOption = document.createElement('label');
			newOption.innerHTML = options[i].textContent;
			newOption.id = 'option_' + i;

			newOptionsDiv.appendChild(newOption);
		}

		newButton.className = 'selectButton';
		newSelect.id = this.select.id;
		newSelect.name = this.select.name;
		newSelect.className = this.select.className == "" ? '' : this.select.attributes[1].nodeValue;
		newSelect.value = this.select.value;
		newSelect.disabled = true;
		newSelect.type = 'text';
		jQuery(newSelect).css('background', '#fff');

		jQuery('#' + this.select.id).replaceWith(newSelect);
		jQuery('#' + newSelect.id).after(newButton).after(newOptionsDiv);
	}
};
/**
 * convert normal image into rounded image
 */
var roundedImages = {
	init: function() {
		jQuery.noConflict();
		var element = jQuery('.rounded'),
			l		= element.length,
			i 		= 0;

		while(l--)
			this.roundImg(element[i++]);
	},

	roundImg: function(ele) {
		var img 		  = jQuery(ele),
			variableWidth = 0,
			outerSpan 	  = document.createElement('span'),
			innerSpan 	  = document.createElement('span');

		img.after(outerSpan);
		jQuery(outerSpan).addClass('outer');
		jQuery(innerSpan).addClass('inner');
		jQuery(outerSpan).css('height', ele.offsetHeight-2);

		if(jQuery.browser.msie && jQuery.browser.version.split('.')[0] < 9) {
			
			if(jQuery('div.withBackground form').length > 0) {
				jQuery(outerSpan).corner("round 10px");
			} else {
				jQuery(outerSpan)[0].appendChild(innerSpan);	
				jQuery(innerSpan).corner("round 10px").parent().css('padding', '2px').corner("round 12px");
				if(ele.nodeName == 'IMG') {
					img.remove();
					jQuery(innerSpan).css('background', 'url("' + ele.src + '") no-repeat center #fff');
				}else if(ele.nodeName == 'DIV') {
					if(jQuery.browser.version.split('.')[0] < 8)
						jQuery(outerSpan).css({'height' : ele.offsetHeight-5});
					else
						jQuery(outerSpan).css({'height' : ele.offsetHeight-2});

					jQuery(outerSpan).find('div.jquery-corner').css({'z-index' : 500});
					jQuery(ele).css({'top': '-2px', 'left': '0', 'z-index': '250'});
					jQuery(innerSpan).find('div.jquery-corner').after(img[0]);
					jQuery(jQuery(innerSpan).find('div.rounded')[1]).remove();
					img.remove();
				}
			}
		} else
			jQuery(img).corner();
		
		if(jQuery('div#prod_header').length > 0 )
			variableWidth = 570;
		else if(jQuery('div.withBackground form').length > 0) {
			variableWidth = ele.offsetWidth;
			jQuery(outerSpan).css('height', ele.offsetHeight + 'px');
		} else 
			variableWidth = 178;
		
		jQuery(outerSpan).css('width', variableWidth + 'px');
		

		if(jQuery.browser.msie && jQuery.browser.version.split('.')[0] == 9)
			jQuery(outerSpan).css('position', 'absolute');

		if(!jQuery.browser.msie && jQuery('div.withBackground form').length > 0)
			jQuery(outerSpan).remove();
	}
};
/**
 * init hover-effect for rounded images with border
 */
var productHover = {
	init: function() {
		jQuery.noConflict();
		if(jQuery('.product a span').length == 0)
			return;

		if(jQuery.browser.msie && jQuery.browser.version.split('.')[0] < 9) {
			this.isIE();
			return;
		}

		jQuery('.product a').mouseover(function() {
			var ele = jQuery(this),
				child = ele.children('span.outer');

			if(child.length == 0)
				return;

			child.css('height', child[0].clientHeight-4);
			child.css('width', '174px');
			child.css('border-width', 3);
		});
		jQuery('.product a').mouseout(function() {
			var ele = jQuery(this),
				child = ele.children('span.outer');

			if(child.length == 0)
				return;

			child.css('height', child[0].clientHeight+4);
			child.css('width', child[0].clientWidth+4);
			child.css('border-width',1);
		});
	},

	isIE: function() {
		jQuery('.product a').mouseover(function() {		
			jQuery(this).addClass('product-hover-ie');
		});
		jQuery('.product a').mouseout(function() {
			jQuery(this).removeClass('product-hover-ie');
		});
	}
};

/**
 * Create the hover-element
 */
var hoverDialog = {
	title: '',
	text: '',

	productInfo: function(title, text) {
		this.title = title;
		this.text = text;

		this.replaceText();
	},

	clearInfo: function() {
		var a = jQuery('div.overlay h2'),
			b = jQuery('div.overlay div.info div p');

		a.empty();
		b.empty();

		a[0].innerHTML = 'loading...';
		jQuery('div.overlay img').css('display', 'inline');
	},

	/**
 	* create the div-tag
 	*/
	createOverlay: function() {		
		if(jQuery('div.product').length < 1)
			return;

		var html = [
		            '<div class="overlay">',
		            '<div class="opacity"></div>',
		            '<div class="info" ><h2></h2>',
		            '<div></div><img src="fileadmin/layout/images/preloader.gif" />',
		            '</div>',
		            '</div>'
		            ];

//		if(jQuery.browser.msie)
			jQuery('div.overlay .opacity').corner();

		jQuery(document.body).append(html.join(''));
	},

	replaceText: function() {
		var head 	= jQuery('div.overlay h2'),
			text 	= jQuery('div.overlay div.info div'),
			newHead = document.createElement('h2'),
			newDiv 	= document.createElement('div'),
			newText = document.createElement('p');

		newHead.innerHTML = this.title;
		newDiv.appendChild(newText);
		head.replaceWith(newHead);
		text.replaceWith(newDiv);
		jQuery(newDiv).children('p').append(this.text);

		jQuery('div.overlay img').css('display', 'none');
	},

	getHeight: function() {
		var transDiv = jQuery('div.overlay .opacity'),
			height = jQuery('div.overlay').innerHeight();

		transDiv.css('height', height);
	},

	positionOfOverlay: function() {
		jQuery(document).mousemove(function(e) {
			if(jQuery('div.overlay').css('display') != 'none') {
				var overlay = jQuery('div.overlay');

				if(e.pageX > (document.width-(overlay.innerWidth()+ overlay.innerWidth()/2)))
					overlay.css('left', e.pageX-20-overlay.innerWidth());
				else
					overlay.css('left', e.pageX+20);

				overlay.css('top', e.pageY);
			}
		});
	}
};

/**
 * Productdescription hover short
 */
var detailHover = {
	init: function() {
		jQuery.noConflict();
		hoverDialog.createOverlay();

		var products = jQuery('#productlist a'),
			l 		 = products.length;

		if(l < 1)
			return;

		while(l--) {
			this.setHover(products[l]);
		}
	},

	setHover: function(element) {
		jQuery(element).mouseover(function(e) {
			var id = parseInt(jQuery(this).parent('div.product')[0].id.split('_')[1]);
			var lang = jQuery('#t3lang').val();

			if(isNaN(id))
				return;

			jQuery.ajax({
					type: 'GET',
					url: 'index.php?eID=product_quickview',
					data: {
						'epimid': id,
						'lang': lang
					},
					dataType: 'json',
					success: function (json) {
						var desc = json[0].description.split('\n'),
							newDesc = [];

						for(var i = 0, l = 2; i<l;++i) {
							newDesc.push(desc[i]);
						}

						hoverDialog.productInfo(json[0].itemnumber, newDesc.join('<br />'));
						hoverDialog.getHeight();
					}				
			});

			hoverDialog.positionOfOverlay();
			jQuery('div.overlay').css('display', 'block');
		});

		jQuery(element).mouseout(function() {
			jQuery('div.overlay').css('display', 'none');
			jQuery('div.overlay .opacity').css('height', '100px');
			hoverDialog.clearInfo();
		});
	}
};

var tabbedContent = {
	header: [],
	cnt: [],

	init: function() {
		jQuery.noConflict();

		var tabCnt  = jQuery('.tabbed_content'),
			l 		= tabCnt.length;
		if(l < 1)
			return;

		while(l--) {
			tabCnt[l].id = 'tabbedCnt_' + l;
			this.tabbedCnt(tabCnt[l]);
		};

		this.changeVisible();
	},

	tabbedCnt: function(htmlObj) {
		var TabCnt 	= htmlObj,
			newDiv 	= document.createElement('div'),
			cntTags = this.splitCnt(htmlObj),
			l		= cntTags.length;

		newDiv.id = TabCnt.id;
		newDiv.className = TabCnt.className;
		newDiv.appendChild( this.splitHeader(htmlObj) );
		for(var i = 0; i<l;++i)
			newDiv.appendChild( cntTags[i] );

		jQuery('#' + TabCnt.id).replaceWith(newDiv);
	},

	createNewHeader: function() {
		var newUl 	= document.createElement('ul'),
			l		= this.header.length;

		for(var i = 0; i<l; ++i) {
			var newLi = document.createElement('li'),
				newA  = document.createElement('a');

			jQuery(newA).attr('id', 'tabHead_' + i);
			jQuery(newA).attr('href', 'javascript:void(0);');
			newA.innerHTML = this.header[i].innerHTML;
			if(i == 0)
				newA.className = 'active';
			newLi.appendChild(newA);
			newUl.appendChild(newLi);
		}

		return newUl;
	},

	createNewCnt: function() {
		var divArray = [],
			l		 = this.cnt.length;

		while(l--) {
			var newDiv  = document.createElement('div');

			newDiv.appendChild(this.cnt[l]);
			newDiv.id 	= 'tab_' + l;
			if(l == 0)
				newDiv.className = 'active';

			divArray[l] = newDiv;
		}
		return divArray;
	},

	splitHeader: function( htmlObj ) {
		var header 	= jQuery('#' + htmlObj.id).children('div.tab').children('h2'),
			l		= header.length;

		while(l--)
			this.header[l] = header[l];

		return this.createNewHeader();
	},

	splitCnt: function( htmlObj ) {
		var cnt = jQuery('#' + htmlObj.id).children('.tab').children('div'),
			l	= cnt.length;

		while(l--) 
			this.cnt[l] = cnt[l];

		return this.createNewCnt();
	},

	changeVisible: function() {
		jQuery('div.tabbed_content ul li a').click(function() {
			var id = parseInt(this.id.split('_')[1]),
				active = jQuery('#tab_' + id),
				siblings 	   = active.siblings('div'),
				siblingsTarget = jQuery(this).parents('li').siblings('li'),
				l		 	   = siblings.length;

				if(active.hasClass('active'))
					return;

				jQuery(this).addClass('active');
				active.addClass('active');

				while(l--) {
					if(siblings[l].className == 'active')
						siblings[l].className = '';
					if(siblingsTarget[l].children[0].className == 'active')
						siblingsTarget[l].children[0].className = '';
				};
		});
	}
};

var leftOptSearch = {
	init: function() {
		jQuery.noConflict();

		var optCats = jQuery('div.option_search'),
			l		= optCats.length;

		while(l--) {
			optCats[l].id = "optionGrp_" + l;
			optCats.children('strong')[l].id= "optionSelect_" + l;

			jQuery(optCats[l]).addClass('active');
			jQuery(optCats[l]).children('strong').addClass('active');

			this.changeVisibility(optCats[l]);
		}
	},

	changeVisibility: function(htmlObj) {
		var ele 	= jQuery(htmlObj),
			header  = ele.children('strong');

		ele.children('strong').remove();
		header.insertBefore(ele);

		header.click (function() {
			var $this = jQuery('#optionGrp_' + jQuery(header)[0].id.split('_')[1]);

			if($this.hasClass('active')){
				$this.removeClass('active');
				jQuery(header).removeClass('active');
			} else {
				$this.addClass('active');
				jQuery(header).addClass('active');
			}
		});
	}
};

var contentSlider = {
	htmlObj 	 : null,
	contentSlide : null,
	timer		 : null,
	duration	 : 500,
	interval	 : 5000,
	maxItems	 : 0,
	slide		 : 0,

	init: function(htmlObj) {
		this.htmlObj 		= htmlObj;
		this.contentSlide 	= jQuery('div#cnt div.slide');

		if(this.contentSlide.length < 1)
			return;
		
		this.htmlObj.children('span.move_left').addClass('inactive');

		this.getContentHeight();
		this.getContentLength();
		this.getSliderLength();
		this.getMoveSlider();

		this.timer = setInterval('contentSlider.moveSlider()', this.interval);
	},
	
	moveSlider: function() {
		var bar 			= jQuery('span.show-block'),
			sliderElement 	= jQuery('div.slide').children('div.slider-element'),
			currentElement 	= jQuery('div.slide div.noDisplay').length > 0 ? jQuery('div.slide div.noDisplay:last').next().next() : jQuery(sliderElement[0]),
			nextElement 	= currentElement.next().next(),
			moveRightButton = bar.next();

		if(moveRightButton.prevAll('span.move_left').hasClass('inactive'))
			moveRightButton.prevAll('span.move_left').removeClass('inactive');

		nextElement.css('left', currentElement[0].offsetWidth);

		currentElement.fadeOut('slow', function() {
			currentElement.addClass('noDisplay');
			nextElement.animate( {'left': '-=' + nextElement[0].offsetWidth}, contentSlider.duration);
		});
		bar.animate( {'left':'+=' + contentSlider.slide + 'px'}, contentSlider.duration/2, function() {
			if( Math.round( (bar[0].offsetLeft + contentSlider.slide) + bar[0].clientWidth ) > 728 ) {
				moveRightButton.addClass('inactive');
				clearInterval(contentSlider.timer);
				contentSlider.timer = null;
			}
		} );
	},

	getContentHeight: function() {
		var contentElements = this.contentSlide.children('div.slider-element'),
			count			= contentElements.length,
			i				= 0,
			maxH			= 0;

		for(var i = 0; i<count; ++i) {
			if(contentElements[i].offsetHeight > maxH)
				maxH = contentElements[i].offsetHeight;
		}

		jQuery('#cnt div.slide').css('height', Math.round(maxH + 49) + 'px');
	},

	getContentLength: function() {
		var contentElements = this.contentSlide.children('div.slider-element');

		this.contentSlide.css( 'width', Math.round(contentElements.length * 765) + 'px' );
	},

	getSliderLength: function() {
		this.maxItems 	= this.contentSlide.children('div.slider-element').length,
			bar 		= this.htmlObj.children('span.show-block');

		if(this.maxItems < 2)
			return;

		var newWidth = (692-( (this.maxItems-1) * parseFloat(138.4)));
		this.slide = ((692 - bar[0].clientWidth) / (contentSlider.maxItems-1));

		bar.css('width', newWidth + 'px');
	},

	getMoveSlider: function() {
		var moveLeft 	= this.htmlObj.children('span.move_left'),
			moveRight 	= this.htmlObj.children('span.move_right');

		moveLeft.click(function(e) {
			if( jQuery(e.target).hasClass('inactive') || jQuery(e.target).hasClass('no_move') )
				return;

			var bar 			= jQuery(this).siblings('span.show-block'),
				sliderElement 	= jQuery('div.slide').children('div.slider-element'),
				currentElement 	= jQuery('div.slide div.noDisplay').length > 0 ? jQuery('div.slide div.noDisplay:last').next().next() : jQuery(sliderElement[sliderElement.length-1]),
				prevElement 	= currentElement.prev().prev(),
				moveLeftButton 	= jQuery(e.target);

			if(contentSlider.timer) {
				clearInterval(contentSlider.timer);
				contentSlider.timer = null;
			}

			if(moveLeftButton.nextAll('span.move_right').hasClass('inactive'))
				moveLeftButton.nextAll('span.move_right').removeClass('inactive');

			currentElement.animate( {'left': '+=' + currentElement[0].offsetWidth}, contentSlider.duration/2, function() {
				prevElement.fadeIn('slow');
				prevElement.removeClass('noDisplay');
			});

			bar.animate( {'left':'-=' + contentSlider.slide + 'px'}, contentSlider.duration, function() {
				if(bar[0].offsetLeft <= 48)
					moveLeftButton.addClass('inactive');
			} );
		});

		moveRight.click(function(e) {

			if( jQuery(e.target).hasClass('inactive') )
				return;

			var bar 			= jQuery(this).siblings('span.show-block'),
				sliderElement 	= jQuery('div.slide').children('div.slider-element'),
				currentElement 	= jQuery('div.slide div.noDisplay').length > 0 ? jQuery('div.slide div.noDisplay:last').next().next() : jQuery(sliderElement[0]),
				nextElement 	= currentElement.next().next(),
				moveLeftSide 	= (692 - bar[0].clientWidth) / (contentSlider.maxItems-1),
				moveRightButton = jQuery(e.target);

			if(contentSlider.timer) {
				clearInterval(contentSlider.timer);
				contentSlider.timer = null;
			}

			if(moveRightButton.prevAll('span.move_left').hasClass('inactive'))
				moveRightButton.prevAll('span.move_left').removeClass('inactive');

			nextElement.css('left', currentElement[0].offsetWidth);

			currentElement.fadeOut('slow', function() {
				currentElement.addClass('noDisplay');
				nextElement.animate( {'left': '-=' + nextElement[0].offsetWidth}, contentSlider.duration);
			});

			bar.animate( {'left':'+=' + contentSlider.slide + 'px'}, contentSlider.duration/2, function() {
				if( Math.round( (bar[0].offsetLeft + contentSlider.slide) + bar[0].clientWidth ) > 728 )
					moveRightButton.addClass('inactive');
			} );
		});
	}
};

var productSlider = {
	htmlObj : null,
	ProductSlide : null,
	duration: 150,

	init: function() {
		this.htmlObj 		= jQuery('div.slider');
		this.ProductSlide 	= jQuery('div.product-slide');
		
		if(this.ProductSlide.length == 0) {
			contentSlider.init(this.htmlObj);
			return;
		}

		var slider = jQuery('#productlist');
		
		
		jQuery('div#preloader').animate({opacity: '0'}, 500, function() {
			
			jQuery('#preloader').remove();
			if(jQuery.browser.msie && jQuery.browser.version.split('.')[0] == 8)
				return;
			else
				slider.animate({opacity: 1}, 1000);
		});

		this.htmlObj.children('span.move_left').addClass('inactive');

		this.getProductsLength();
		this.getSliderLength();
		if( this.ProductSlide.children('div.product').length > 4 )
			this.getMoveSlider(this.htmlObj);
	},

	getProductsLength: function() {
		var products = this.ProductSlide.children('div.product');

		this.ProductSlide.css( 'width', Math.round(products.length * 195) + 'px' );
	},

	getSliderLength: function() {
		var count 	= this.ProductSlide.children('div.product').length,
			bar 	= this.htmlObj.children('span.show-block');

		if(count < 5)
			return;

		var newWidth = Math.round( 692-( 12 * (count-4) ) );

		bar.css('width', newWidth + 'px');
	},

	getMoveSlider: function() {
		var moveLeft 	= this.htmlObj.children('span.move_left'),
			moveRight 	= this.htmlObj.children('span.move_right');

		moveLeft.click(function(e) {
			var bar 			= jQuery(this).siblings('span.show-block'),
				count 			= jQuery('div.product-slide').children('div.product').length,
				moveLeftButton 	= jQuery(e.target),
				moveLeftSide 	= Math.round((692 - bar[0].clientWidth) / (count-4));

			if( !moveLeftButton.hasClass('inactive') || bar[0].offsetLeft >= 38 ) {
				bar.animate( {'left':'-=' + moveLeftSide + 'px'}, productSlider.duration, function () {
					if(bar[0].offsetLeft <= 48)
						moveLeftButton.addClass('inactive');
				} );

				if(moveLeftButton.nextAll('span.move_right').hasClass('inactive'))
					moveLeftButton.nextAll('span.move_right').removeClass('inactive');

				if(jQuery.browser.msie && jQuery.browser.version.split('.')[0] == 7)
					jQuery('div.product-slide').animate( {'left':'+=187px'}, productSlider.duration );
				else if(jQuery.browser.msie && jQuery.browser.version.split('.')[0] > 7)
					jQuery('div.product-slide').animate( {'left':'+=190px'}, productSlider.duration );
				else 
					jQuery('div.product-slide').animate( {'left':'+=195px'}, productSlider.duration );
			}
		});

		moveRight.click(function(e) {
			var bar 			= jQuery(this).siblings('span.show-block'),
				count 			= jQuery('div.product-slide').children('div.product').length,
				moveRightButton = jQuery(e.target);

			if(count == 4)
				return;

			var moveLeftSide 	= Math.round((692 - bar[0].clientWidth) / (count-4));

			if( !moveRightButton.hasClass('inactive') ) {
				bar.animate( {'left':'+=' + moveLeftSide + 'px'}, productSlider.duration, function() {
					if( Math.round( (bar[0].offsetLeft + moveLeftSide) + bar[0].clientWidth ) > 728 )
						moveRightButton.addClass('inactive');
				} );

				if(moveRightButton.prevAll('span.move_left').hasClass('inactive'))
					moveRightButton.prevAll('span.move_left').removeClass('inactive');

				if(jQuery.browser.msie && jQuery.browser.version.split('.')[0] == 7)
					jQuery('div.product-slide').animate( {'left':'-=187px'}, productSlider.duration );
				else if(jQuery.browser.msie && jQuery.browser.version.split('.')[0] > 7)
					jQuery('div.product-slide').animate( {'left':'-=190px'}, productSlider.duration );
				else
					jQuery('div.product-slide').animate( {'left':'-=195px'}, productSlider.duration );
			}
		});
	},
	
	preLoad: function() {
		var productSlider = jQuery('#productlist'),
			preLoadDiv = jQuery(document.createElement('div'));
		
		preLoadDiv[0].id = 'preloader';

		preLoadDiv.append('<img src="fileadmin/layout/images/preloader.gif" />');
		productSlider.after(preLoadDiv);
		
		if(jQuery.browser.msie && jQuery.browser.version.split('.')[0] == 8)
			jQuery('#preloader').addClass('msie8');
		else
			jQuery('#productlist').css({'opacity': '0'});
	}
};

var ProductFlash = {
	showFlash: function( type ){
		if( type == 1 )
			jQuery('#zoomFlash').show();
		if( type == 2 )
			jQuery('#rotationFlash').show();
	},

	hideFlash: function(){
		jQuery('#rotationFlash').hide();
		jQuery('#zoomFlash').hide();
	}
};

var VariantsSwitcher = {
	images : null,
	spans: null,
	active: null,

	init: function()
	{
		this.images = jQuery('#prod_header img.variantImg');
		this.spans = jQuery('.variantHover');

		this.active = 0;

		this.spans.hover(function(){
			position = jQuery( this ).parent().parent().prevAll().length;				
			if( VariantsSwitcher.images[ position ] )
			{
				VariantsSwitcher.images[ VariantsSwitcher.active ].style.display = 'none';				
				VariantsSwitcher.images[ position ].style.display = 'inline';
				VariantsSwitcher.active = position;
			}
		});

		this.spans.mouseout(function(){

			VariantsSwitcher.images[ VariantsSwitcher.active ].style.display = 'none';				
			VariantsSwitcher.images[ 0 ].style.display = 'inline';
			VariantsSwitcher.active = 0;
		});
	}
};

/**
 * main application for global functions
 */
var Application = {

	init: function()
	{
		//SubNav.init();
		//selector.init();
		leftOptSearch.init();
		NewsSlider.init();
		roundedImages.init();
		productHover.init();
		detailHover.init();
		tabbedContent.init();
		productSlider.init();
		VariantsSwitcher.init();
	}	
};
productSlider.preLoad();
$(document).ready( function() {Application.init();} );
