jQuery.noConflict();

/*
 * General DOM ready statemenets
 * 
 */
jQuery(function($) {
	
	if (($.browser.msie) && ($.browser.version <= 6)) {
		$('#nav > li:first-child').addClass('first-child');
		$('#nav > li, #gallery ul li, #other-products ul li, #slideshow ul li').hover(function(){ $(this).addClass('over')}, function(){ $(this).removeClass('over') })
		$('#contact .submit, .product .row .submit').hover(function(){ $(this).attr('id','over')}, function(){ $(this).attr('id','') })
	}
	
	if (($.browser.msie) && ($.browser.version <= 7)) {
		$('#other-products ul li:last-child').addClass('last-child')
	}
	
	/*$('#nav li').mouseover(function(){
		$(this).addClass('over');
		$(this).find('ul').css('display','block');
	}).mouseout(function(){
		$(this).removeClass('over');
		$(this).find('ul').css('display','none');
	});*/
	
	$('#slider-inner').scrollable({ size: 3 }).circular();
	
	//Gallery image switch
	$('#gallery li').find('img').each(function(){
		var $imgSrc = $(this).parent().attr('href');
		var $nmimgSrc = $(this).attr('src');
		var $parent = $(this).parent();
		$parent.click(function(){
			$('#bigImg').find('img').fadeOut(function(){
				$(this).attr('src',$imgSrc);
				$(this).parent().attr('href',$imgSrc);
			}).fadeIn();
		});
	});
	
	//Cycle images
	$('#cycle1').cycle();
	$('#cycle2').cycle({ delay: 2000 });
	$('.cycle-a').mouseover(function(){
		$(this).next().css('display','block');
	}).mouseout(function(){
		$(this).next().css('display','none');
	});
	$('.cms-index-index .cycle-a').mouseover(function(){
		$(this).next().css('display','block');
	}).mouseout(function(){
		$(this).next().css('display','block');
	});
	$('#cycle-wrap .hover-box').mouseover(function(){
		$(this).css('display','block');
	});
	//Jquery Alphanumeric
	$('.qty').numeric();
	
	//Uniform Select
	$('.product .details form').find('select').uniform()
	$('#single-stock .product form').find('select').uniform()
	
	/*
	 * Slider
	 */
	var $slideshow = $('#slideshow').find('ul');
	var $lookslideshow = $('.category-look-book #slideshow').find('ul');
	width = 0;
	$slideshow.find('li').each(function(){
		var li = $(this).width();
		width += li;
	}).end().width(width);
	ulwidth=width;
	leftdefault = $(window).width()-width;
	width -= $(window).width()+6;
	
	var step = width/99;
	$slideshow.css('left',leftdefault*0.5);
	$lookslideshow.css('left',0);
	if(ulwidth>970){
		var $slideBar = $('#slide-bar').slider({
			slide: function(event, ui){
				left = -ui.value*step;
				$slideshow.css('left',left);
				scrolling = false;
			},
			change: function(event, ui){
				left = -ui.value*step;
				$slideshow.css('left',left);
			}
		});
		$('#slide-bar').slider({ value: 50 });  
		$('.category-look-book #slide-bar').slider({ value: 0 });  
			
		$('#slider-next, #slider-prev').mousedown(function(event){
			scrolling = true;
			($(event.target).is('#slider-next'))?goNext():goPrev(); //See if we are going forward or backwards											
		}).mouseup(function(event){
			scrolling = false;
		});
		
		$('#slideshow').mousewheel(function(event, delta) {
			
			if (delta > 0){
				scrolling = false;
				goNext(); //See if we are going forward or backwards				
			}else if (delta < 0){
				goPrev();
			}
		});
		$('#slideshow').mouseover(function(){
			$('body').css('overflow','hidden');
		}).mouseout(function(){
			$('body').css('overflow','auto');
		});
	}
	
	$('#nav a').each(function(){
		if(!jQuery.inArray($(this).attr('href'),document.location.href.split("?"))){
			$(this).parent().addClass('active');
		}
	});
});

var scrolling = true;

function goNext(){
	var $slideBar = jQuery('#slide-bar');
	var value = $slideBar.slider('value'); //getting the slider value
	value += 1; //Going to the next step in the right direction
	$slideBar.slider('value',value); //Setting the new value
	if (scrolling) setTimeout('goNext()', 100);			
}

function goPrev(){
	var $slideBar = jQuery('#slide-bar');
	var value = $slideBar.slider('value'); //getting the slider value
	value -= 1; //Going to the next step in the right direction
	$slideBar.slider('value',value); //Setting the new value
	if (scrolling) setTimeout('goPrev()', 100);			
}
