
/* -------------------------------------
	author:			Roman Muntyanu
	email:			roman.muntyanu@webartstudio.md
	project:		BAGOBAG
	developed by:	Web Art Pro
------------------------------------- */

jQuery(function(){

	// ----------------------  aside blocks slider
	var sbArr = ['1', '1'];
	
	var savedSba = getCookie('sbaCookie');
	if( savedSba != null ){
		var savedSbArr = savedSba.split('|');
		for( i = 0; i < savedSbArr.length; i++ ){
			if( savedSbArr[i] == '1' ){
				jQuery(jQuery('.slide-button')[i]).parent().css({ marginLeft: '0px' });
			}else{
				jQuery(jQuery('.slide-button')[i]).addClass('slide-back').parent().css({ marginLeft: '-184px' });
			}
			sbArr[i] = savedSbArr[i];
		}
	}
	
	var doc_body = $('body');
	jQuery('.slide-button').bind('click', function(){
		var slideButton = jQuery(this);
		var sbInd = jQuery('.slide-button').index(this);
		
		if( slideButton.hasClass('slide-back') ){
			slideButton.removeClass('slide-back');
			adjustMainWidth();
			slideButton.parent().animate({ marginLeft: '0px' }, 500);
			setSbCookie(sbInd, '1');
		}else{
			slideButton.addClass('slide-back');
			slideButton.parent().animate({ marginLeft: '-184px' }, 500);
			jQuery('.main').animate({ marginLeft: '40px' }, 500);
			setSbCookie(sbInd, '0');
		}
	});
	
	function setSbCookie(ind, state){
		sbArr[ind] = state;
		var sbaStr = sbArr.join('|');
		setCookie('sbaCookie', sbaStr);
	}
	
	
	var jb_param = gup('jb');
	
	var anc_slide_time = 600;
	var anc_slide_flag = true;
	jQuery('.anc-sub-list').each(function(){
		var anc_sub_list = jQuery(this);
		if(anc_sub_list.find('.bb-active').length > 0 || anc_sub_list.find('.yb-sub').not('.yellow-button, .yellow-wide-button').length > 0){
			anc_sub_list.slideDown(anc_slide_time);
		}
		else if(jb_param == 1){
			anc_sub_list.slideDown(anc_slide_time);
		}
		else{
			anc_sub_list.hide();
		}
	});
	
	jQuery('.anc-item > a').bind('mouseover', function(){
		var anchor = jQuery(this);
		anchor.next('.anc-sub-list').slideDown(anc_slide_time);
		
		anchor.parent().siblings('.anc-item').each(function(){
			jQuery('.anc-sub-list', this).slideUp(anc_slide_time);
		});
	});
	
	jQuery('.anc-sub-item > a').bind('mouseover', function(){
		var anchor = jQuery(this);
		anchor.next('.anc-sub-list').slideDown(anc_slide_time);
		
		anchor.parent().siblings('.anc-sub-item').each(function(){
			jQuery('.anc-sub-list', this).slideUp(anc_slide_time);
		});
	});
	
	
	function gup(name){
		name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		var regexS = "[\\?&]"+name+"=([^&#]*)";
		var regex = new RegExp( regexS );
		var results = regex.exec(window.location.href);
		if( results == null )
			return "";
		else
			return results[1];
	}
	
	/**
	jQuery('.anc-list').mouseout(function(){
		var bb_active = jQuery('.anc-sub-list .bb-active');
		if(bb_active){
			bb_active.parent().parent().slideDown(anc_slide_time);
		}
	});
	
	jQuery('.anc-item').hover(
		function(){
			anc_slide_flag = true;
			jQuery('.anc-sub-list', this).slideDown(anc_slide_time); // , function(){ anc_slide_flag = true; }
		},
		function(){
			var anc_item = jQuery(this);
			if(anc_slide_flag && anc_item.find('.anc-sub-list .bb-active').length == 0){
				anc_slide_flag = false;
				jQuery('.anc-sub-list', this).slideUp(anc_slide_time, function(){ anc_slide_flag = true; });
			}
		}
	);
	/**/
	
	
	
	// ---------------------- ## aside blocks slider
	
	// ----------------------  top menu styles adjustment on window resize
	var bmWidth = jQuery('.bagobag-menu').width();
	var bmMarginTop = jQuery('.bagobag-menu').css('marginTop');
	
	adjustTopMenuWidth();
	if( !jQuery(document.body).hasClass('cms-home') ){
		adjustMainWidth();
	}
	
	var doc_body = $('body');
	jQuery(window).resize(function(){
		if(doc_body.width() > 915) {
			adjustTopMenuWidth();
			if( !jQuery(document.body).hasClass('cms-home') ){
				adjustMainWidth();
			}
		}
	});
	
	function adjustTopMenuWidth(){
		var hiWidth = jQuery('.header-inner').width();
		if( hiWidth < 1230 ){
			var cbmw = hiWidth - 20;
			if( !jQuery.browser.msie ){
				jQuery('.bagobag-menu').width(cbmw).css({ marginTop: '10px' }).parent().parent().parent().css({ minHeight: '191px' }); // 191px  205px
			}else{
				jQuery('.bagobag-menu').width(cbmw).css({ marginTop: '10px' }).parent().height('176px').parent().height('191px').parent().height('191px');
			}
		}else{
			if( !jQuery.browser.msie ){
				jQuery('.bagobag-menu').width(bmWidth).css({ marginTop: bmMarginTop }).parent().parent().parent().css({ minHeight: '125px' });
			}else{
				jQuery('.bagobag-menu').width(bmWidth).css({ marginTop: bmMarginTop }).parent().height('110px').parent().height('125px').parent().height('125px'); // .height('110px')
			}
		}
	}
	
	function adjustMainWidth(){
        var aside_nav = jQuery('.aside-navigation');
        if(aside_nav.length > 0){
            var bodyWidth = jQuery(document.body).width();
            // var mainWidth = jQuery('.main').width();
			
			var mainWidth = jQuery('.main-container').width();
			var asideNavWidth = aside_nav.width();

			var diff = asideNavWidth - (bodyWidth - mainWidth)/2 + 60; // + 14
			
			// var adjusted = mainWidth - 2*diff;
			// jQuery('.main').width(adjusted + 'px');
		
			if(jQuery('.slide-button').hasClass('slide-back')){
				jQuery('.main').css({ marginLeft: '60px' });
			}else{
				jQuery('.main').css({ marginLeft: diff });	
			}			
        }
	}
	
	// ---------------------- ## top menu styles adjustment on window resize
	
	
	// ----------------------  products on main on window resize
	
	var cpcWidth = jQuery('.products-container').width();
	var modInd = 3;
	
	if( cpcWidth < 1280 ){
		modInd = 2;
		jQuery('.products-container').width('845px');
	}
	
	jQuery('.product-wrapper').each(function(i){
		if( (i + 1) % modInd == 0 ){
			jQuery(this).addClass('row-last');
		}
	});
	
	
	jQuery(window).resize(function(){
		var stdWidth = jQuery('.std').width();
		
		jQuery('.row-last').removeClass('row-last');
		if( stdWidth < 1280 ){
			jQuery('.products-container').width('845px');
			
			jQuery('.product-wrapper').each(function(i){
				if( (i + 1) % 2 == 0 ){
					jQuery(this).addClass('row-last');
				}
			});
		}else{
			jQuery('.products-container').width('1280px');
			
			jQuery('.product-wrapper').each(function(i){
				if( (i + 1) % 3 == 0 ){
					jQuery(this).addClass('row-last');
				}
			});
		}
	});
	
	// ---------------------- ## products on main on window resize
	
	
	// -------------------------- gallery on main
	
	/**
	var allNum = jQuery('.ic-image').length;
	var n = 0;
	jQuery('.ic-image').hide();
	jQuery(jQuery('.ic-image')[n]).show();

	var fadeInTime = 1000;
	var fadeOutTime = 600;
	var paused = false;

	setInterval(function(){
		if( paused ){
			return -1;
		}else{
			jQuery('.bg-none').removeClass('bg-none');
			n++;
			if( n == allNum ){
				n = 0;
			}
		
			jQuery('.ic-image:visible').fadeOut(fadeOutTime, function(){
				jQuery(jQuery('.ic-image')[n]).fadeIn(fadeInTime);
				jQuery(jQuery('.t-layer')[n]).addClass('bg-none');
			});
		}
	}, 10000);

	
		
	jQuery('.left-control').bind('click', function(){
		var cNum = jQuery('.ic-image').index( jQuery('.ic-image:visible') );
		jQuery('.ic-image').hide();
		jQuery('.bg-none').removeClass('bg-none');
		if( cNum == 0 ){
			n = allNum - 1;
		}else{
			n = cNum - 1;
		}
		jQuery(jQuery('.ic-image')[n]).fadeIn(fadeInTime);
		jQuery(jQuery('.t-layer')[n]).addClass('bg-none');
	});

	jQuery('.right-control').bind('click', function(){
		var cNum = jQuery('.ic-image').index( jQuery('.ic-image:visible') );
		jQuery('.ic-image').hide();
		jQuery('.bg-none').removeClass('bg-none');
		if( cNum == allNum - 1 ){
			n = 0;
		}else{
			n = cNum + 1;
		}
		jQuery(jQuery('.ic-image')[n]).fadeIn(fadeInTime);
		jQuery(jQuery('.t-layer')[n]).addClass('bg-none');
	});

	
	jQuery(jQuery('.t-layer')[n]).addClass('bg-none');
	
	jQuery('.t-layer').bind('click', function(){
		var pointInd = jQuery('.t-layer').index(this);
		n = pointInd;
		
		jQuery('.bg-none').removeClass('bg-none');
		jQuery(this).addClass('bg-none');
		jQuery('.ic-image').hide();
		jQuery(jQuery('.ic-image')[pointInd]).fadeIn(fadeInTime);
	});
	/**/
	
	
	// adjusts gallery image position on window resize
	var icImgWidth = jQuery('.ic-image').width();
	adjustIcImgMargin();
	jQuery(window).resize(function(){
		adjustIcImgMargin();
	});
	
	function adjustIcImgMargin(){
		var imgContWidth = jQuery('.image-container').width();
		if( icImgWidth > imgContWidth ){
			var icMarLeft = -Math.floor( (icImgWidth - imgContWidth)/2 );
			jQuery('.ic-image').css({ position: 'relative', marginLeft: icMarLeft + 'px' });
		}else{
			jQuery('.ic-image').css({ marginLeft: '4px' });
		}
	}
	
	
	/*
	jQuery('.banners .pause').bind('click', function(){
		paused = true;
		jQuery(this).addClass('invisible');
		jQuery('.banners .play').removeClass('invisible');
	});

	jQuery('.banners .play').bind('click', function(){
		paused = false;
		jQuery(this).addClass('invisible');
		jQuery('.banners .pause').removeClass('invisible');
	});
	*/
	
	/*
	if( jQuery.browser.msie ){
		jQuery('.banners').hover(
			function(){ jQuery('.b-controls').show(); },
			function(){ jQuery('.b-controls').hide(); }
		);
	}
	*/
	
	
	/*
	var ppwObj = jQuery('.t-layer-wrapper');
	for( i = 0; i < allNum; i++ ){
		ppwObj.append('<span class="t-layer" />');
	}
	*/
	// -------------------------- ## gallery on main
	
	
	// -------------------------- product flip effect
	jQuery('.revert').hide();
	
	jQuery(".flip-pad a:not(.revert)").bind("click", function(){
		var athis = jQuery(this);
		var revObj = athis.parent().find('a').filter('.revert');
		var infoFlag;
		
		var proWrapInd = jQuery('.product-wrapper').index( athis.parent().parent() );
		
		jQuery("#" + athis.attr('class') ).flip({
			direction: athis.attr('rel'),
			color: athis.attr('rev'),
			content: jQuery( '#' + athis.attr('name') ).html(),
			speed: 300,
			// transparent: "transparent",
			// toColor: "transparent",
			dontChangeColor: true,
			onBefore: function(){ 
				athis.parent().find('a').hide();
			},
			onEnd: function(){
				
				infoFlag = athis.parent().next().children().filter('.os-content').is(':visible');
				setTimeout(function(){
					if( infoFlag ){
						revObj.fadeIn('slow');
					}else{
						athis.fadeIn('slow');
					}
				}, 500);
				
				/*	
				activateThumbnailSlider();
				activateThumbnailCarousel();
				TB_init();
				adjustThumbRel(athis, proWrapInd);
				*/	
				
				activateThumbnailCarousel(proWrapInd);
				activateThumbnailHover();
				var osgObjs = athis.parent().next().find('a').filter('.osg-link');
				// activateGalleryLinks(osgObjs);
				// tb_init('a.thickbox');
			}
		});
		
		athis.hide();
		
		return false;
	});
	
	jQuery(".revert").bind("click", function(){
		var rthis = jQuery(this);
		jQuery("#" + rthis.attr('rel') ).revertFlip();
		
		return false;
	});
	
	/*
	function adjustThumbRel(obj, proWrapInd){
		obj.parent().parent().find('ul').filter('.osg-list-'+ proWrapInd +':first').find('a').filter('.thickbox').attr('rel', 'th_gallery_' + proWrapInd);
	}
	*/
	
	// -------------------------- ## product flip effect
	
	
	// -------------------------- product gallery fish eye effect
	var animTime = 100;
	
	var initialHeight = '62px';
	var asideHeight = '75px';
	var maxHeiht = '90px';
	
	var initialWidth = '46px';
	var asideWidth = '55px';
	var maxWidth = '65px';
	
	var initialBorder = '0px';
	var asideBorder = '5px';
	var maxBorder = '10px';
	
	var osListWidth = '320px';
	
	var osgFlag = true;
	
	var initialMargin = '0px';
	var activeMargin = '-15px'
	
	var initialBorder = '1px';
	var activeBorder = '2px';
	
	/**
	function activateFisheye(){
		jQuery('.osg-item').hover(
			function(){
				if( osgFlag ){
					osgFlag = false;
					jQuery(this).parent().width(osListWidth);
					jQuery(this).animate({ height: maxHeiht, width: maxWidth, marginTop: activeMargin, borderWidth: activeBorder }, animTime, function(){ osgFlag = true; });
				}
			},
			function(){
				jQuery(this).animate({ height: initialHeight, width: initialWidth, marginTop: initialMargin, borderWidth: initialBorder }, animTime);
			}
		);
	}
	
		jQuery('.osg-item').bind('mouseover', function(){
			if( osgFlag ){
				osgFlag = false;
				var osgtObj = jQuery(this);
				
				osgtObj.parent().width(osParentWidth);
				
				osgtObj.animate({ height: maxHeiht, width: maxWidth, marginTop: maxBorder }, animTime, function(){ osgFlag = true; });
				
				
				osgtObj.prev().animate({ height: asideHeight, width: asideWidth, marginTop: asideBorder }, animTime);
				osgtObj.next().animate({ height: asideHeight, width: asideWidth, marginTop: asideBorder }, animTime);
				
				osgtObj.prev().prev().animate({ height: initialHeight, width: initialWidth, marginTop: initialBorder }, animTime);
				osgtObj.next().next().animate({ height: initialHeight, width: initialWidth, marginTop: initialBorder }, animTime);
				
			}
		});
	
	
	function activateFisheye(){
		$('#fisheye').Fisheye({
		maxWidth: 55,
		items: 'li',
		// itemsText: 'span',
		container: '.fisheyeContainter',
		itemWidth: 45,
		proximity: 90,
		valign : 'bottom'
	});
	}
	/**/
	
	/**
	function activateThumbnailHover(){
	
		jQuery('.osg-thumbnail').width('50px').height('60px');
		
		jQuery('.osg-thumbnail').hover(
			function(){
				if( osgFlag ){
				    osgFlag = false;
					jQuery(this).animate({ width: '60px', height: '70px', margin: '0px' }, animTime, function(){ osgFlag = true; });
				}
			},
			function(){
				jQuery(this).animate({ width: '50px', height: '60px', margin: '0 5px' }, animTime);
			}
		);
	}
	/**/
	
	// -------------------------- ## product gallery fish eye effect
	
	
	// -------------------------- product gallery carousel
	/*  */
	
	function activateThumbnailCarousel(proWrapInd){
		
		var osgClass = '.osg-list-' + proWrapInd + ':visible';
		
		jQuery(osgClass).find('li').css({ width: '46px', height: '80px' });
		jQuery(osgClass).jcarousel({
			 visible : 5, scroll: 5, buttonNextHTML: "<div>&nbsp;</div>", buttonPrevHTML: "<div>&nbsp;</div>" // 2
		});
		
		var jbClass = '.jb-list-' + proWrapInd + ':visible';
		if( jQuery(jbClass).length > 0 ){
			jQuery(jbClass).jcarousel({
				 visible : 4, scroll: 4, buttonNextHTML: "<div>&nbsp;</div>", buttonPrevHTML: "<div>&nbsp;</div>"
			});
		}
	}
	
	var osgiFlag = true;
	var osgiAnimTime = 200;
	var asideTime = 200;
	var osgAboveTime = 150;
	
	var initMargin = '12px 6px';
	var initWidth = '81%';
	var initHeight = initWidth;
	
	var asideMargin = '7px 2px';
	var asideWidth = '91%';
	var asideHeight = asideWidth;
	
	var wideMargin = '0';
	var wideWidth = '100%';
	var wideHeight = '105%';
	
	var osgTimer;
	
	function activateThumbnailHover(){
	
		jQuery('.osg-item').hover(
			function(){
				var osgThis = jQuery(this);
				osgTimer = setTimeout(function(){
					if(osgiFlag){
						osgiFlag = false;
						osgThis.addClass('osgi-wide').find('a').animate({ margin: wideMargin, width: wideWidth, height: wideHeight }, osgiAnimTime, function(){ osgiFlag = true; 
							osgThis.prev().addClass('osgi-aside').find('a').animate({ margin: asideMargin, width: asideWidth, height: asideHeight }, asideTime);
							osgThis.next().addClass('osgi-aside').find('a').animate({ margin: asideMargin, width: asideWidth, height: asideHeight }, asideTime);
						});
					}
				}, osgAboveTime);
			},
			function(){
				// if(osgiFlag){
					clearTimeout(osgTimer);
					jQuery('.osgi-wide').removeClass('osgi-wide');
					jQuery('.osgi-aside').removeClass('osgi-aside');
					
					jQuery(this).find('a').css({ margin: initMargin, width: initWidth, height: initHeight });
					jQuery(this).prev().find('a').css({ margin: initMargin, width: initWidth, height: initHeight });
					jQuery(this).next().find('a').css({ margin: initMargin, width: initWidth, height: initHeight  });
				// }
			}
		);
		
	}
	
	/*
	function activateGalleryLinks(osgObjs){
		
		osgObjs.bind('click', function(){
			var osgPath = jQuery(this).attr('href');
			var actInd = osgObjs.index(this) + 1;
		
			var osgClone = jQuery(this).parent().parent().clone();
			osgClone.removeClass().attr('style', '').addClass('fgt-list cfx');
			osgClone.find('li').removeClass().attr('style', '').css({ width: '160px', height: '160px'}).addClass('fgt-item');
			osgClone.find('a').attr('style', '').removeClass().addClass('fgt-link');
			osgClone.find('img').removeClass().addClass('fgt-thumbnail');
			
			jQuery('.fg-thumbnails').empty().append(osgClone);
			jQuery('#fg_image').attr('src', osgPath);
			
			var wWidth = jQuery(window).width();
			var wHeight = jQuery(window).height();
			
			$(document.body).prepend('<div class="fgt-floating-container" />');
			
			jQuery('.fgt-floating-container').append('<div class="fgt-opacity-layer" />');
			
			jQuery('.fgt-opacity-layer, .fgt-floating-container').css({ width: wWidth, height: wHeight });
			
			var fgClone = jQuery('#floating_gallery').clone();
			var fgWidth = jQuery('#floating_gallery').width();
			var fgLeft = Math.floor( (wWidth - fgWidth)/2 );
			
			fgClone.css({ display: 'block', top: '50px', left: fgLeft }); // visibility: 'visible',
			
			jQuery('.fgt-floating-container').append(fgClone);
			
			activateFloatingCarousel();
			
			var numberOfVisible = 4;
			var fgJN = fgClone.find('div').filter('.jcarousel-next');
			var numsToClick = Math.floor(actInd / numberOfVisible);
			
			setTimeout(function(){
			for( i = 0; i < numsToClick; i++ ){
				fgJN.click();
			}
			}, 500);
			
		
			jQuery('.fg-close').bind('click', function(){
				jQuery(this).parent().parent().remove();
			});
			
			return false;
		});		
		
	}
	*/
	
	/*
			var counter = 1;
			var fgTimer;
			
			fgTimer = setTimeout(function(){
				if( counter <= numsToClick ){
					fgJN.click();
					counter++;
					fgTimer;
				}else{
					clearTimeout(fgTimer);
				}
			}, 1000);
			*/
	// -------------------------- ## product gallery carousel  &nbsp;
	
	
	// -------------------------- floating layer gallery
	/*
	function activateFloatingCarousel(){
		
		jQuery('.fgt-list:visible').jcarousel({
			 visible : 4, scroll: 4, buttonNextHTML: "<div>&nbsp;</div>", buttonPrevHTML: "<div>&nbsp;</div>"
		});
		
		jQuery('.fgt-link').bind('click', function(){
			var fgtPath = jQuery(this).attr('href');
			jQuery('#fg_image').fadeOut(500, function(){
				jQuery(this).attr('src', fgtPath).fadeIn(1000);
			});
			
			return false;
		});
	}
	*/
	
	// $('#floating_gallery').flayer({ outerClose : false, bgcolor: "#000000", opacity: '0.8', closeClass : 'fg-close' });
	
	// -------------------------- ## floating layer gallery
	
	
	
	
	// -------------------------- thumbnail slider
	
	/* 
	
	slider = new Array();
	big = new Array();
	big["width"] = 70;
	big["height"] = 62;
	big["height2"] = big["height"] + 28;

	big['marginTop0'] = 0;

	small = new Array();

	small["width"] = 46;
	small["height"] = 62;

	small["width1"] = 60;

	small["height1"] = small["height"] + 13;
	small["height2"] = small["height"] + 0;

	small['marginTop1'] = 6;
	small['marginTop2'] = 12;


	font = new Array();
	font["big"] = 16;
	font["small"] = 12;
	timer = -1;

	var animTime = 600;
	
	var actual = 3;

	function equilibrate() {
		jQuery('.slider ul li').each(function(i) {
			d = Math.abs(actual - i);
			var a = jQuery(this);
			var img = a.children('a').children('img');
			switch(d) {
				case 0:
					a.animate({width: big["width"], height: big["height2"], marginTop: big['marginTop0']}, animTime);
				break;
				case 1:
					if (slider[i] == 1) {
						slider[i] = 0;
						a.css({display: 'inline', width: '0px', height: '0px'});
						img.css({width: '0px', height: '0px'});
					}
					a.animate({width: small["width1"], height: small["height1"], marginTop: small['marginTop1']}, animTime);
				break;
				case 2:
					
					if (slider[i] == 1) {
						slider[i] = 0;
						a.css({display: 'inline', width: '0px', height: '0px'});
					}
					a.animate({width: small["width"], height: small["height2"], marginTop: small['marginTop2']}, animTime);
				break;
				default:
					if (slider[i] != 1) {
						slider[i] = 1;
						a.hide('fast'); 
					}
				break;
			}
		});
	}
	function actual_change(diff) {
		if (actual + diff > 0 && actual + diff < max) {
			actual = actual + diff;
			return true;
		}
		return false;
	};

			jQuery('.slider ul').css('overflow', 'hidden');
			jQuery('.slider ul').prepend('<li class="osg-item"><a class=""><img src="/skin/frontend/default/bagobag/images/vide.png" alt="" /></a></li>');
			max = jQuery('.slider ul li').size();
		
		function activateThumbnailSlider(){
		
			jQuery('.slider ul li').each( function(i) {
				d = Math.abs(actual - i);
				var a = jQuery(this);
				var img = a.children('a').children('img');
				switch(d) {
					case 0:
						a.css({display: 'block', width: big["width"]+'px', height: big["height2"]+'px', marginTop: big['marginTop0']+'px'});
					break;
					case 1:
						a.css({display: 'block', width: small["width1"]+'px', height: small["height1"]+'px', marginTop: small['marginTop1']+'px' });
					break;
					case 2:
						a.css({display: 'block', width: small["width"]+'px', height: small["height2"]+'px', marginTop: small['marginTop2']+'px'});
					break;
					default:
						a.css({display: 'none', width: '0px', height: '0px'});
					break;
				}
			});
			jQuery('#butleft').bind('click', function () {
				var bLeft = jQuery(this);
			
				if (actual_change(-1)){
					equilibrate();
				}
				navDisabled(bLeft);
				
				return false;
			});
			jQuery('#butright').bind('click', function () {
				var bRight = jQuery(this);
				
				if (actual_change(+1)){
					equilibrate();
				}
				navDisabled(bRight);
				
				return false;
			});
			
			function navDisabled(navObj){
				if( actual == 1 ){
					navObj.addClass('left-disabled');
				}else if( actual == max - 1 ){
					navObj.addClass('right-disabled');
				}else{
					jQuery('.left-disabled').removeClass('left-disabled');
					jQuery('.right-disabled').removeClass('right-disabled');
				}
			}
			
			jQuery('#playpause').bind('click', function () {
				var a = jQuery('#playpause').children('img').attr('src');
				var a = a.split("/");
				if (a[a.length - 1] == 'pause.png') {
					
				}
				else {
					next();
					timer = window.setInterval("next()", 2200);
					jQuery('#playpause').children('img').attr('src', 'images/pause.png');
				}

				return false;
			});
			jQuery('.slider ul li a').bind('click', function () {
				
			});
		}
		
	function timer_stop() {
		var a = jQuery('#playpause').children('img').attr('src');
		var a = a.split("/");
		if (a[a.length - 1] == 'pause.png') {
			jQuery('#playpause').children('img').attr('src', 'images/playred.png');
			window.clearInterval(timer);
		}
	}
	function next() {
		if (actual_change(+1))
			equilibrate();
	}
	*/
	
	// -------------------------- ## thumbnail slider
	
	
	
	// -------------------------- content gallery
	/**
	jQuery('.osg-link').bind('click', function(){
		return false;
	});
        
	activateGalleryLinks(jQuery('.osg-link'));
	/**/
	jQuery('.os-gallery .osg-link').live('click', function(){
		var a = this.href || this.alt;
		var t = '<a class="image-fullsize" target="_blank" title="" href="' + a + '">fullsize image</a>' || null;
		var g = this.rel || false;
		tb_show(t,a,g);
		this.blur();
		return false;
	});
	
	

	jQuery(document).bind('keypress', function(event){
		switch (event.keyCode){
			case 27:
				jQuery('.fgt-floating-clone').remove();
			break;
		}
	});
	
	if(jQuery('.content-slider').length > 0){
		jQuery('.content-slider').cycle({
			fx: 'wipe', // scrollVert  shuffle  turnDown  scrollHorz growY blindZ wipe
			pager: '.content-slider-pager',
			timeout: 0, // 10000
			speed: 500
		});
	}
	
	if(jQuery('.film-list').length > 0){
		jQuery('.film-list').cycle({
			fx: 'scrollVert',
			timeout: 0,
			speed: 400,
			next:   '.fc-up',
			prev:   '.fc-down'
		});
	}
	
    /**
    if(jQuery.browser.msie)
    {
        var th_width = 120;
        var th_height = 153;
        jQuery('.cat-media-list .osg-thumbnail').each(function(){
            var osg = jQuery(this);
            var osg_width = osg.width();
            var osg_height = osg.height();
            
            var new_width = (osg_width > th_width - 1) ? th_width + "px" : "auto";
            var new_height = (osg_height > th_height - 1) ? th_height + "px" : "auto";
            
            osg.width(new_width);
            osg.height(new_height);
        });
    }
    /**/
    
	// activateGalleryLinks(jQuery('.film-list .osg-link'));
	
	// -------------------------- ## content gallery
	
	
	// -------------------------- anfrage button
	if(jQuery('.aside-nav-content .bb-active').length > 0){
		var anfrageFlag = jQuery('.aside-nav-content .bb-active').attr('href').indexOf('anfrage');
		if( anfrageFlag != -1 ){
			jQuery('.switcher-contacts-wrapper .wide-button-black').addClass('active');
		}
	}
	// -------------------------- ## anfrage button
	
	if($('#image_container').length > 0) {
		$('#image_container').cycle({ 
			fx:     'fade',  // fadeZoom
			speed:  700, 
			timeout: 10000, 
			next: '#right_control',
			prev: '#left_control',
			pager:  '#thumb_container', 
			
			pagerAnchorBuilder: function(idx, slide) { 
				// return '<li><a href="#"><img src="' + slide.src + '" width="50" height="50" /></a></li>'; 
				
				return '<div class="thumnail"><img src="' + slide.lang + '" alt="" class="t-image" /><span class="t-layer"></span></div>';
			} 
		});
	}
	
	
	
}); // ----- ## dom ready end


/**/
function getThumbnailPrefixStr(win_width, win_height){
    var max_width = 660;
    var max_height = 820;
    var f_height = 640;
    var prefix_str = '/thumbs/products/660x820';
    
    if( (win_height >= f_height) && (win_height < max_height) )
    {
        var r_height = 730;
        var r_width = Math.floor(max_width*r_height/max_height);
    }
    else if(win_height < f_height)
    {
        var r_height = 600;
        var r_width = Math.floor(max_width*r_height/max_height);
    }else{
        var r_height = max_height;
        var r_width = max_width;
    }
    prefix_str = '/thumbs/products/' + r_width + 'x' + r_height;
    
    return prefix_str;
}

function activateGalleryLinks(osgObjs)
{
    osgObjs.bind('click', function(event){
        event.preventDefault();
        var osg_obj = jQuery(this);
        var actInd = jQuery(this).parent().parent().find('a.osg-link').index(this);
        // clone is used because img src might contain quotes
        var osg_list = osg_obj.parent().parent().clone(); 
        
        // screen size
        var win_width = jQuery(window).width();
		var win_height = jQuery(window).height();
        var prefix_str = getThumbnailPrefixStr(win_width, win_height);
        
        var gallery_wrapper_clone = jQuery('#templates .fgt-floating-container').clone();
        gallery_wrapper_clone.addClass('fgt-floating-clone');
        var list_clone = gallery_wrapper_clone.find('.fgt-list');
        
        var fullsize_links = [];
        osg_list.find('a').each(function(){
			var cur_a = jQuery(this);
			var a_href = cur_a.attr('href');
            fullsize_links.push(a_href);
            
            if(jQuery.browser.msie)
            {
                var base_url = jQuery('#base_url_field').val();
                base_url = base_url.replace("/index.php/", "");
                if(a_href.indexOf(base_url) != -1)
                {
                    a_href = a_href.replace(base_url, ""); //    /qweqwe/i
                }
            }
			
            cur_a.removeAttr('style').removeClass().addClass('fgt-link');
			cur_a.find('img').removeClass().addClass('fgt-thumbnail').attr({ src: prefix_str + a_href });
            
            list_clone.append(cur_a);
		});
        
        list_clone.find('a').each(function(){
            jQuery(this).wrap('<li class="fgt-item"><div class="fgt-box"><div class="fgt-box-inner"></div></div></li>');
        });
        list_clone.find('.fgt-item').each(function(ind, element){
            jQuery(element).append('<a href="' + fullsize_links[ind] + '" title="" target="_blank" class="fgt-fullsize-link">fullsize image</a>');
        });
        
        gallery_wrapper_clone.css({ width: win_width, height: win_height});
        gallery_wrapper_clone.find('.fgt-opacity-layer, .fgt-content-layer').css({ width: win_width, height: win_height});
        
        
        var list_height = win_height - 40;
        var list_width = Math.floor(660*list_height/820);
        if(list_width > 660){
            list_width = 660;
        }
        
        // adjusts layout of list inner elements
        gallery_wrapper_clone.find('.fgt-list, .fgt-item, .fgt-box').height(list_height + 'px');
		if(jQuery.browser.msie){
			gallery_wrapper_clone.find('.fgt-list, .fgt-item, .fgt-box').css({ width: list_width + 'px', background: 'none'});
		}
       gallery_wrapper_clone.find('.fgt-thumbnail').css({ maxWidth: list_width + 'px', maxHeight: list_height + 'px'});
       
        // middle position for controls
        gallery_wrapper_clone.find('.osg-control-left').css({ left: '-50px', top: (win_height/2 - 20) + 'px'});
		gallery_wrapper_clone.find('.osg-control-right').css({ right: '-50px', top: (win_height/2 - 20) + 'px'});
        
        // gallery close controls
        gallery_wrapper_clone.find('.fg-close').bind('click', function(){
			jQuery('.fgt-floating-clone').remove();
		});
        gallery_wrapper_clone.find('.fgt-content-layer').bind('click', function(event){
            if($(event.target).hasClass('fgt-content-layer')){
                jQuery('.fgt-floating-clone').remove();
            }
		});
        
        jQuery(document.body).prepend(gallery_wrapper_clone);
        
        // cycle the gallery
        jQuery('.fgt-list:visible').cycle({
            fx:     'scrollHorz',
            startingSlide: actInd,
            timeout: 0, 
            speed: 500,
            next:   '.osg-control-right, .fgt-link',
            prev:   '.osg-control-left'
        });
        
        // remove white bg in IE
        if(jQuery.browser.msie){
            jQuery('.fgt-item').css({ background: 'none' });
        }
    });
} // end of activateGalleryLinks
/**/


/**
function activateGalleryLinks(osgObjs)
{	
	osgObjs.bind('click', function(){
		var osgPath = jQuery(this).attr('href');
		var actInd = jQuery(this).parent().parent().find('a.osg-link').index(this); // + 1
		var adjustFlag = false;
		var showAlt = false;
	
		var osgClone = jQuery(this).parent().parent().clone();
		if(osgClone.hasClass('adjust')){
			adjustFlag = true;
		}
		if(osgClone.hasClass('show-alt')){
			showAlt = true;
		}
		osgClone.removeClass().attr('style', '').addClass('fgt-list cfx');
		osgClone.find('li').removeClass().attr('style', '').addClass('fgt-item'); // .css({ width: '160px', height: '160px'})
		// osgClone.find('a').attr('style', '').removeClass().addClass('fgt-link');
		// osgClone.find('img').removeClass().addClass('fgt-thumbnail');
		
		osgClone.find('a').each(function(){
			var cur_a = jQuery(this);
			var a_href = cur_a.attr('href');
			cur_a.attr('style', '').removeClass().addClass('fgt-link');
			cur_a.find('img').removeClass().addClass('fgt-thumbnail').attr('src', a_href);
            
            cur_a.wrap('<div class="fgt-box"><div class="fgt-box-inner"></div></div>');
		});
		
		
		
		jQuery('.fg-thumbnails').empty().append(osgClone);
		// jQuery('#fg_image').attr('src', osgPath);
		
		var wWidth = jQuery(window).width();
		var wHeight = jQuery(window).height();
		
		jQuery(document.body).prepend('<div class="fgt-floating-container" />');
		
		jQuery('.fgt-floating-container').append('<div class="fgt-opacity-layer" />');
		
		jQuery('.fgt-opacity-layer, .fgt-floating-container').css({ width: wWidth, height: wHeight });
		
		var fgClone = jQuery('#floating_gallery').clone();
		var fgWidth = jQuery('#floating_gallery').width();
		var fgLeft = Math.floor( (wWidth - fgWidth)/2 );
		
		fgClone.css({ display: 'block', top: '0px', left: fgLeft }); // visibility: 'visible', top: '20px'
		
		jQuery('.fgt-floating-container').append(fgClone);
		
		
		// activateFloatingCarousel();
		
		// var numberOfVisible = 4;
		// var fgJN = fgClone.find('div').filter('.jcarousel-next');
		// var numsToClick = Math.floor(actInd / numberOfVisible);
		
		// setTimeout(function(){
		// for( i = 0; i < numsToClick; i++ ){
        // 			fgJN.click();
		// }
		// }, 500);
		
		
		var fgttHeight = jQuery('.fgt-thumbnail:first').height();
		if( fgttHeight > wHeight ){
			fgttHeight = wHeight - 20;
		}
		jQuery('.fgt-list:visible, .fgt-item').height(fgttHeight + 'px');
		var fgttWidth = Math.floor(660*fgttHeight/820);
		if(jQuery.browser.msie){
			jQuery('.fgt-item').css({ width: fgttWidth + 'px'});
		}
		if(!adjustFlag)
        {
			jQuery('.fgt-thumbnail').css({ maxWidth: fgttWidth + 'px', maxHeight: fgttHeight + 'px' });
            jQuery('.fgt-box').css({ height: fgttHeight + 'px' });
		}
		jQuery('.fg-thumbnails:visible').css({ marginTop: (wHeight - fgttHeight)/2 });
		
		
		jQuery('.osg-control-left:visible').css({ left: '-50px', top: (wHeight/2 - 20) + 'px'});
		jQuery('.osg-control-right:visible').css({ right: '-50px', top: (wHeight/2 - 20) + 'px'});
		
		// jQuery('.fgt-thumbnail').bind('click', function(){
		// 	jQuery('.osg-control-right:visible').click();
		// 	return false;
		// });
        
		var fgtListExists = jQuery('.fgt-list:visible').length;
		if( fgtListExists != 0 ){
			jQuery('.fgt-list:visible').cycle({
				fx:     'scrollHorz', // scrollVert  shuffle  turnDown  scrollHorz
				startingSlide: actInd,
				timeout: 0, // 10000
				speed: 500,
				// after: onAfter,
				next:   '.osg-control-right, .fgt-link',
				prev:   '.osg-control-left'
			});
		}
		
		if(adjustFlag){
			jQuery('.fgt-link').wrap('<div class="table-wrapper" />');
			jQuery('.fgt-link').css({ display: 'table-cell', verticalAlign: 'middle' });
			jQuery('.fgt-thumbnail').css({ width: 'auto', height: 'auto', verticalAlign: 'middle' });
		}
		
		
		// function onAfter(){
		// 	if(showAlt){
		// 		var cur_fgt_height = jQuery(this).find('img').height();
		// 		var aw_bottom = Math.floor((win_height - cur_fgt_height)/2);
		// 		jQuery(this).find('div.alt-wrapper').css({ bottom: aw_bottom });
		// 	}
		// }
		
		
		if(showAlt){
			var fgt_offset = jQuery('.fgt-list:visible').offset().top;
			var first_fgt_offset = jQuery('.fgt-thumbnail:first').offset().top;
			first_fgt_offset = Math.floor(first_fgt_offset);
			// console.log(fgt_offset);
			// console.log(first_fgt_offset);
			var aw_bottom = Math.floor((first_fgt_offset - fgt_offset)/2 + 26);
			
			jQuery('.fgt-thumbnail').each(function(){
				var cur_fgt = jQuery(this);
				var cur_alt = cur_fgt.attr('alt');
				cur_fgt.parent().parent().append('<div class="alt-wrapper"><span class="alt-text">' + cur_alt + '</span></div>');
			});
			jQuery('.alt-wrapper').css({ bottom: aw_bottom + 'px'});
		}
		
		jQuery('.fg-close').bind('click', function(){
			jQuery(this).parent().parent().remove();
		});
        jQuery('.fgt-opacity-layer').bind('click', function(){
			jQuery(this).parent().remove();
		});
		
		return false;
	});		
}
/**/
	
		/*
		var counter = 1;
		var fgTimer;
		
		fgTimer = setTimeout(function(){
			if( counter <= numsToClick ){
				fgJN.click();
				counter++;
				fgTimer;
			}else{
				clearTimeout(fgTimer);
			}
		}, 1000);
		*/
// -------------------------- ## product gallery carousel  &nbsp;

// -------------------------- floating layer gallery	
function activateFloatingCarousel(){
		
	jQuery('.fgt-list:visible').jcarousel({
		 visible : 4, scroll: 4, buttonNextHTML: "<div>&nbsp;</div>", buttonPrevHTML: "<div>&nbsp;</div>"
	});

	jQuery('.fgt-link').bind('click', function(){
		var fgtPath = jQuery(this).attr('href');
		jQuery('#fg_image').fadeOut(500, function(){
			jQuery(this).attr('src', fgtPath).fadeIn(1000);
		});
		
		return false;
	});
}

	















