jQuery(document).ready(function(){
	
	//Product Thumbnails
	var startValue = 1;
	var totalPages = jQuery('.productShowcase .thumbNavigator .thumbs div').children().size() / 4;
	var leftArrow = jQuery('.productShowcase .thumbNavigator a.leftArrow');
	var rightArrow = jQuery('.productShowcase .thumbNavigator a.rightArrow');
	if(totalPages <= 1){
		jQuery(rightArrow).css('visibility','hidden');
	}
	
	jQuery(leftArrow).click(function(e){
		e.preventDefault();
		jQuery('.productShowcase .thumbNavigator .thumbs div').animate({'left' : '+=360px'},'slow');
		startValue--;
		if(startValue <= 1){
			jQuery(this).css('visibility','hidden');			
		}
		if(startValue < totalPages){
			jQuery(rightArrow).css('visibility','visible');
		}
	});
	jQuery(rightArrow).click(function(e){
		e.preventDefault();		
		jQuery('.productShowcase .thumbNavigator .thumbs div').animate({'left' : '-=360px'},'slow');
		startValue++;
		if(startValue > 1){
			jQuery(leftArrow).css('visibility','visible');			
		}
		if(startValue >= totalPages){
			jQuery(this).css('visibility','hidden');
		}
	});
	
	jQuery('.productShowcase .thumbNavigator .thumbs div a').mouseenter(function(){
		jQuery('.productShowcase .thumbNavigator .thumbs div a').removeClass('selected');
		jQuery(this).addClass('selected');
		//jQuery('.productShowcase .imageHolder a img').hide();
		jQuery(jQuery(this).attr('href')).show();
	});
	
	//Viewer controls
	var startValueViewer = 1;
	var totalPagesViewer = jQuery('.imageViewer .thumbNailNavigatorViewer .thumbs div').children().size() / 4;
	var leftArrowViewer = jQuery('.imageViewer .thumbNailNavigatorViewer a.leftArrow');
	var rightArrowViewer = jQuery('.imageViewer .thumbNailNavigatorViewer a.rightArrow');
	if(totalPagesViewer <= 1){
		jQuery(rightArrowViewer).css('visibility','hidden');
	}
	
	jQuery(leftArrowViewer).click(function(e){
		e.preventDefault();
		jQuery('.imageViewer .thumbNailNavigatorViewer .thumbs div').animate({'left' : '+=360px'},'slow');
		startValueViewer--;
		if(startValueViewer <= 1){
			jQuery(this).css('visibility','hidden');			
		}
		if(startValueViewer < totalPagesViewer){ 
			jQuery(rightArrowViewer).css('visibility','visible');
		}
	});
	jQuery(rightArrowViewer).click(function(e){
		e.preventDefault();		
		jQuery('.imageViewer .thumbNailNavigatorViewer .thumbs div').animate({'left' : '-=360px'},'slow');
		startValueViewer++;
		if(startValueViewer > 1){
			jQuery(leftArrowViewer).css({
				'visibility' : 'visible',
				'zoom' : 1
			});			
		}
		if(startValueViewer >= totalPagesViewer){
			jQuery(this).css({
				'visibility' : 'hidden',
				'zoom' : '1'
			});
		}
	});
	
	jQuery('.imageViewer .thumbNailNavigatorViewer .thumbs div a').mouseenter(function(){
		jQuery('.imageViewer .thumbNailNavigatorViewer .thumbs div a').removeClass('selected');
		jQuery(this).addClass('selected');
		jQuery('.imageViewer #zoom01 img').load(function(){
			resetZoomImg();
		});
		jQuery('.imageViewer #zoom01 img').attr('src',jQuery(this).get(0).href);
		jQuery('.imageViewer .gzoomSlider').slider('value',0);
		//jQuery('.imageViewer #zoom01 img').css({margin:"auto",left:0,top:0});
	});
	function resetZoomImg(){
		//alert(jQuery('.imageViewer #zoom01 img').width() +"  "+jQuery('.imageViewer #zoom01').width());
		var containerWidth = jQuery('.imageViewer #zoom01').width();
		var imgWidth = jQuery('.imageViewer #zoom01 img').width();
		//alert(containerWidth +" "+imgWidth)
		var left = (containerWidth-imgWidth)/2;
		var ig =jQuery('#zoom01 img').css({position: "absolute",left: left,top:0});
	}
	
	jQuery(document).bind('cbox_complete', function(){
		resetZoomImg();		
	})
	
	
	//Awards
	/*var awardsLeft = '.footerInfo .awardsHolder .leftArrow';
	var awardsRight = '.footerInfo .awardsHolder .rightArrow';
	var awardsSlider = '.footerInfo .awardsHolder .awards .slider';
	var numberOfAwards = jQuery(awardsSlider).children().size();
	var currentAward = 1;
	
	if(numberOfAwards > 0){
		jQuery(awardsLeft).click(function(e){
			e.preventDefault();
			if(currentAward > 1){
				jQuery(awardsSlider).animate({'left' : '+=305px'},'slow');
				currentAward--;	
			}else{
				var moveTotal = 305 * (numberOfAwards-1)+'px';
				currentAward = numberOfAwards
				jQuery(awardsSlider).animate({'left' : '-'+moveTotal},'slow');
			}
		});
		
		jQuery(awardsRight).click(function(e){
			e.preventDefault();
			if(currentAward < numberOfAwards){
				jQuery(awardsSlider).animate({'left' : '-=305px'},'slow');
				currentAward++;	
			}else{
				var moveTotal = 305 * (numberOfAwards-1)+'px';
				currentAward = 1;
				jQuery(awardsSlider).animate({'left' : '0px'},'slow');
			}
		});	
	}
	
	//lightbox functionality for image viewer
	var jQueryimgViewerImage = jQuery('.productShowcase .imageViewer #zoom01 img');
	jQuery("#zoom01").gzoom({
		sW: 447,
        sH: 284,
        lW: 1341,
        lH: 852,
        framewidth: 0,
        loaderContent: '', 
        lighbox : false
	});
	
	jQuery('.productShowcase .imageHolder a').colorbox({
		width: '843px',
		//height: '480px',
		inline: true, 
		href: '.imageViewer',
		opacity: 0.7,
		close: ' ',
		scrolling: false,
		onOpen: function(){
			jQueryimgViewerImage.attr('src', jQuery(this).attr('href'));
		},
		onCleanup: function(){			
			jQuery('.productShowcase .imageViewer .gzoomSlider').slider('value',0);
		}
	});*/
	
	//lightbox functionality for video player
	jQuery('.demos .item .videoThumb a, .videos .item .videoThumb a').colorbox({
		opacity: 0.7,
		close: ' ',
		iframe:true, 
		//innerWidth:425, innerHeight:344
		width: '910px',
		height: '553px',
		scrolling: false
	});



//lightbox functionality for contact page
		jQuery('.bottomContentC .leftA a.contact').colorbox({
		opacity: 0.7,
		close: ' ',
		//iframe:true, 
		//innerWidth:425, innerHeight:344
		width: '1030px',
		height: '720px',
		scrolling: false
	});

//lightbox functionality for contact page
		jQuery('#pageFooter ul.footercontact li.contact-frm a, #mainNavigation ul.level3 li a.top-contact-frm').colorbox({
		opacity: 0.7,
		close: ' ',
		//iframe:true, 
		//innerWidth:425, innerHeight:344
		width: '1030px',
		height: '720px',
		scrolling: false
	});

//lightbox functionality for right block  page
		jQuery('.bottomContentC .tabContent .right .rightblock a.oem, .bottomContentC .tabContent .right .rightblock a.channel').colorbox({
		opacity: 0.7,
		close: ' ',
		//iframe:true, 
		//innerWidth:425, innerHeight:344
		width: '1030px',
		height: '720px',
		scrolling: false
	});

//lightbox functionality for right block  page
		jQuery('.bottomContentC .tabContent .right .mapLocation a.map').colorbox({
		opacity: 0.7,
		close: ' ',
		//iframe:true, 
		//innerWidth:425, innerHeight:344
		width: '1030px',
		height: '720px',
		scrolling: false
	});
	
	//lightbox functionality for user review
	jQuery('a.writeReview').colorbox({
		width: '762px',
		minHeight: '480px',
		inline: true, 
		href: '.userReviewBox',
		opacity: 0.7,
		close: ' ',
		scrolling: false		
	});
	
	//lightbox functionality for buy now
	jQuery('.productShowcase .add-to-cart .btn-cart').colorbox({
		Width: '968px',
		inline: true, 
		href: '.buyNowContainer',
		opacity: 0.7,
		close: ' ',
		scrolling: false		
	});

	//Cart functionality
	jQuery('.headerToolbox .showCart').click(function(e){
		e.preventDefault();
		var coordinates = $(this).offset();
		var left = coordinates.left - 370;
		var top = coordinates.top;
		//console.log(coordinates);
		$('#cartOverview').css({
			'position': 'absolute',
			'display': 'block',
			'top': top+'px',
			'left': left+'px'
		})
	});
	
	jQuery('#cartOverview .closeBtn').click(function(e){
		e.preventDefault();
		$(this).parent().css({'display': 'none'});
	});

//Product Category Slider
	var totalItems = jQuery('.productScrollerContainer .items .itemSlider .item').length;
	var totalWidth = totalItems * (jQuery('.productScrollerContainer .items .itemSlider .item').first().width() + 8);
	//fix slider width
	jQuery('.productScrollerContainer .items .itemSlider').width(totalWidth+'px');
	
	var container = jQuery('.productScrollerContainer .sliderGallery .items');
	var ul = jQuery('.itemSlider', container);
	var itemsWidth = ul.innerWidth() - container.outerWidth();
	
	jQuery('.productScrollerContainer .sliderWidget .slider').slider({
			min: 0,
			max: itemsWidth,
			handle: '.handle',
			stop: function (event, ui) {
					ul.animate({'left' : ui.value * -1}, 500);
			},
			slide: function (event, ui) {
					ul.css('left', ui.value * -1);
			}
	});
	if(totalItems <= 4){
		jQuery('.productScrollerContainer .sliderWidget').css('visibility','hidden');
	}
	
	jQuery('.productScrollerContainer .itemSlider .item a.productThumb').mouseover(function(e){		
		var href = jQuery(this).attr('hover:rel');
		var windowWidth = 1000;
		var boxWidth = jQuery(href).width();
		var leftOffset = 0;
		var background = '';
		if(jQuery(this).offset().left + boxWidth < windowWidth){
			leftOffset = jQuery(this).position().left + 264;
			jQuery('.productScrollerContainer .productDescription img').css('left','9px');
			background = 'transparent url('+SKIN_URLL+') no-repeat 0 50%';
		}else{
			leftOffset = jQuery(this).position().left - (boxWidth + 10);
			jQuery('.productScrollerContainer .productDescription img').css('left','308px');
			background = 'transparent url('+SKIN_URLR+') no-repeat 308px 50%';
		}
		jQuery(href).css({
			'left' : leftOffset,
			'top' : '5px',
			'background': background
		})
		jQuery(href).show();
	}).mouseout(function(e){
		var href = jQuery(this).attr('hover:rel');		
		jQuery(href).hide();
	});
	
	jQuery('.productScrollerContainer .productDescription').mouseover(function(e){
		jQuery(this).show();
	}).mouseout(function(e){
		jQuery(this).hide();
	});
	
	//accordion for productcatcat
	jQuery('.productCategoryCategory .bottomContent .tabContent .filterBox ul li.collapseNormal a.collapseHandle').click(function(e){
		e.preventDefault();
		var href = jQuery(this).attr('href');
		if(jQuery(href).css('display') == 'none'){
			jQuery(jQuery(this).attr('href')).show('blind',{direction: 'vertical'});
			//jQuery('a.collapseHandle').addClass('expand-content');
		}else{
			jQuery(jQuery(this).attr('href')).hide('blind',{direction: 'vertical'});
		}		
	});
	

		jQuery('.productCategoryCategory .bottomContent .tabContent .filterBox .topControls a.cal').click(function(e){
		e.preventDefault();
		
		/* put a code for reset value..
		jQuery('.productCategoryCategory .bottomContent .tabContent .filterBox ul li.collapseNormal .collapsibleContent').each(function(){
			if(jQuery(this).css('display') != 'none'){
				jQuery(this).hide('blind',{direction: 'vertical'});
			}
		})*/
	});

	//Support FAQ question collapse
	jQuery('.supportPage-bottomContent .faq .memoryFaq .item a.handle').click(function(e){
		e.preventDefault();
		var target = jQuery(this).attr('href');
		jQuery(target).css('display','block');
	});

	//Calendar for blog page
	jQuery('.contentHolder-right .archives .items .left .calendarReplacement').datepicker();
})

