//****************************************	
//
//		date: 08/30/2011
//		version: 1.0
//		client: Revation Studios
//		author: Jason Wynne
//		
//
//****************************************	


$(document).ready(function(){
	// for slideshow
	var curSlide = 0;
	var nextSlide;
	var fadeOutSpeed = 1000;
	var topZ = 15;
	var bottomZ = 10;
	var intervalTime = 6000; //in milliseconds
	
	// for products
	
	var curProduct = 0;
	var nextProduct = 0;
	
	// for bottom bar
	
	var isUp;
	var isIE7 = 0;
	
	
	// check cookie for botttom bar placement
	
	var barCookie = $.cookie('bottom_location');


	if(barCookie==null){
		barCookie==0;
		isUp = 0;
	}
	if(barCookie==0){
		$('.bottom').css('bottom', '0');
		isUp = barCookie;
		$('.connect-tab').css('background-position','0 0');
		$('.footer').css('height','510px');
	}
	if(barCookie==1){
		$('.bottom').css('bottom', '-182px');
		isUp = barCookie;
		$('.connect-tab').css('background-position','0 -120px');
		$('.footer').css('height','350px');
	}


	// begin slideshow home
	
	$('.slide'+curSlide).css('display', 'block');
	$('.ps-content'+curProduct).css('display', 'block');
	
	var t = setInterval( imageRotate , intervalTime );
	
	function imageRotate() {
		if(curSlide<4){
			nextSlide = curSlide+1;
		}
		if(curSlide==4){
			nextSlide = 0
		}
		
		$('.slide'+nextSlide).css({'display':'block','opacity':'0','z-index': topZ});
		$('.slide'+curSlide).css({'z-index': bottomZ});
		$('.slide'+nextSlide).stop(true).animate({'opacity': '1'}, fadeOutSpeed, function() {
					changeSlideComplete();
				});

		
	
	}
	
	function changeSlideComplete(){
		$('.slide'+curSlide).css({'display':'none','opacity':'0'});
		curSlide = nextSlide;
		
	}
	
	
//  below for product changer

	$('.ps-btn').each(function(index) {
		$(this).addClass('ps-btn'+index);
		$(this).click(function() {
				var isActive = $(this).hasClass('active-product');
				if(isActive==false){
					$(this).addClass('active-product');
					productChange(index);	
			 	}
			}).mouseover(function() {
				var isActive = $(this).hasClass('active-product');
				if(isActive==false){
					productMouseOver(index);
				}
			}).mouseout(function() {
				var isActive = $(this).hasClass('active-product');
				if(isActive==false){
					productMouseOut(index);
				}
			});
	});

	
	function productChange(i){
		productMouseOut(curProduct);
		$('.ps-btn'+curProduct).removeClass('active-product');
		nextProduct = i;
		$('.ps-content'+curProduct).css({'display':'none'});
		$('.ps-content'+nextProduct).css({'display':'block'});

		curProduct=nextProduct;
		
		
		//console.log(curProduct);
	}
	
	function productMouseOver(i){
			$('.ps-btn'+i).css('backgroundPosition','0 0');
	}
	
	function productMouseOut(i){
		if(i==0){
			$('.ps-btn0').css('backgroundPosition','0 -87px');
			}
		if(i!=0){
			$('.ps-btn'+i).css('backgroundPosition','0 -54px');
			}
	}
	
	$('.wp-image-98').each(function(index) {
	$(this).mouseover(function() {
		
				$(this).attr('src', 'http://revation.craftsmen.mn/wp-content/uploads/2011/08/learn-more-btn-over.png');

			}).mouseout(function() {

				$(this).attr('src', 'http://revation.craftsmen.mn/wp-content/uploads/2011/08/learn-more-btn.png');
				
			});
			
		});
		

	$('.slides').mouseover(function() {
			
				$('.wp-image-98').attr('src', 'http://revation.craftsmen.mn/wp-content/uploads/2011/08/learn-more-btn-over.png');

			}).mouseout(function() {

				$('.wp-image-98').attr('src', 'http://revation.craftsmen.mn/wp-content/uploads/2011/08/learn-more-btn.png');
				
			});
			
			

		
		
// detect browser and ignore IE7


if ( $.browser.msie ) {
	var ieBrowserVersion = ( parseInt($.browser.version, 10) );
	//console.log(ieBrowserVersion);
	if(ieBrowserVersion==7){
  		isIE7=1;
  		}
}

// the bottom bar up and down functionality 

if(isIE7==0){
	$('.connect-tab').click(function() {
				//console.log('click');
				if(isUp==0){
					$('.bottom').animate({'bottom': '-182px'}, 250, 'easeOutQuart', function() {
						$('.connect-tab').css('background-position','0 -120px');
						$('.footer').css('height','340px');
							isUp=1;
							$.cookie('bottom_location', '1', { expires: 1, path: '/' });
					});	
				}
				if(isUp==1){
					$('.bottom').animate({'bottom': '0'}, 250, 'easeOutQuart', function() {
						$('.connect-tab').css('background-position','0 0');
						$('.footer').css('height','510px');
							isUp=0;
							$.cookie('bottom_location', '0', { expires: 1, path: '/' });
					});	
				}
			}).mouseover(function() {
				//console.log('over');
				if(isUp==0){
					$('.connect-tab').css('background-position','0 -60px');
				}
				if(isUp==1){
					$('.connect-tab').css('background-position','0 -180px');
				}
			}).mouseout(function() {
				//console.log('out');
				if(isUp==0){
					$('.connect-tab').css('background-position','0 0');
				}
				if(isUp==1){
					$('.connect-tab').css('background-position','0 -120px');
				}
			});
}
		
		
if(isIE7==1){
	$('.footer').css('height','340px');	
	$('.connect-tab').css('background-position','0 -240px');
}




///////   END DOCUMENT READY FUNCTION  ///////
});
