// JavaScript Document
$(function(){
	$('#filterList1').hide();
	$('#filterList2').hide();
	$('#filterList6').hide();
	
	//var tid = setInterval(scrollLeft, 5500);
	
	//Collapsible filter list sections
	$('#showList1').click(function() {
		if($('#filterList1').is(':hidden')){
		$('#showList1').addClass('downArrow');
		$('#filterList1').slideDown(300);
		return false;
		}else {
		$('#showList1').removeClass('downArrow');
		$('#filterList1').slideUp(300);
		return false;
		}
	});
	$('#showList2').click(function() {
		if($('#filterList2').is(':hidden')){
		$('#showList2').addClass('downArrow');
		$('#filterList2').slideDown(300);
		return false;
		}else {
		$('#showList2').removeClass('downArrow');
		$('#filterList2').slideUp(300);
		return false;
		}
	});
	
	$('#showList6').click(function() {
		if($('#filterList6').is(':hidden')){
		$('#showList6').addClass('downArrow');
		$('#filterList6').slideDown(300);
		return false;
		}else {
		$('#showList6').removeClass('downArrow');
		$('#filterList6').slideUp(300);
		return false;
		}
	});
	
	//Code for home page main slider
	//Click functions for slider buttons
	$('.scrollLeft').click(function() {
		//abortTimer();
		scrollLeft();
		return false;
	  });
	  
	$('.scrollRight').click(function() {
		//abortTimer();
		scrollRight();
		return false;
	 });
	
	var $currSlide = $('#slideStart');
	var $slidePrevious;
	var $slideNext;

	//Check if animation is at the beginning of slides
	if($currSlide.prev(".bigSlide").length == 0){
		$slidePrevious = $('#slideEnd');
	}else{
		$slidePrevious = $currSlide.prev(".bigSlide");
	}

	//Check if animation is at the end of slides
	if($currSlide.next(".bigSlide").length == 0){
		$slideNext = $('#slideStart');
	}else{
		$slideNext = $currSlide.next(".bigSlide");
	}
	
	function scrollLeft(){
		//Do not execute function if animation in process
		if ($('.bigSlide:animated').length) {
			return false;
		}

		//Change z-index so current slide is on top
		$currSlide.css({'z-index' : '2', 'width' : '1100px'});
		$slidePrevious.css({'z-index' : '0', 'width' : '1000px'});
		$slideNext.css({'z-index' : '0', 'width' : '1000px'});
			
		//Push next slide to the right
		$slidePrevious.hide().animate({"left": "+=1000px"});
			
		//Scroll current and next slide to left
		$currSlide.animate({"left": "-=1000px"}, 2500);
		$slidePrevious.animate({"left": "-=1000px"}, 2500).show();
	
		//Return slide to 0 and call update once animation complete
		$currSlide.hide(100).animate({"left": "0"}, {complete: function() {
			reassignVariables();
		}
	});			
		  return false;
		/*if($('#sliderContent1').is(':visible')){
			
			//Change z-index so current slide is on top
			$('#sliderContent1').css({'z-index' : '2', 'width' : '1000px'});
			$('#sliderContent2').css({'z-index' : '0', 'width' : '800px'});
			
			//Push next slide to the right
			$('#sliderContent2').hide().animate({"left": "+=900px"});
			
			//Scroll current and next slide to left
		    $('#sliderContent1').animate({"left": "-=900px"}, 2500);
			$('#sliderContent2').animate({"left": "-=900px"}, 2500).show();

			//Return slide to 0
		    $('#sliderContent1').hide(100).animate({"left": "0"});			
			
		}else if($('#sliderContent2').is(':visible')){

			//Change z-index so current slide is on top
			$('#sliderContent2').css({'z-index' : '2', 'width' : '1000px'});
			$('#sliderContent3').css({'z-index' : '0', 'width' : '800px'});
			
			//Push next slide to the right
		    $('#sliderContent3').hide().animate({"left": "+=900px"});

			//Scroll current and next slide to left
		    $('#sliderContent2').animate({"left": "-=900px"}, 2500);
			$('#sliderContent3').animate({"left": "-=900px"}, 2500).show();

			//Return slide to 0
		    $('#sliderContent2').hide(100).animate({"left": "0"});
		}else if($('#sliderContent3').is(':visible')){
			//Change z-index so current slide is on top
			$('#sliderContent3').css({'z-index' : '2', 'width' : '1000px'});
			$('#sliderContent1').css({'z-index' : '0', 'width' : '800px'});
			
			//Push next slide to the right
		    $('#sliderContent1').hide().animate({"left": "+=900px"});

			//Scroll current and next slide to left
		    $('#sliderContent3').animate({"left": "-=900px"}, 2500);
			$('#sliderContent1').animate({"left": "-=900px"}, 2500).show();

			//Return slide to 0
		    $('#sliderContent3').hide(100).animate({"left": "0"});
		}
		*/
	  }

	  function scrollRight(){
		//Do not execute function if animation in process
		if ($('.bigSlide:animated').length) {
			return false;
		}

		//Change z-index so current slide is on top
		$currSlide.css({'z-index' : '2', 'width' : '1100px'});
		$slidePrevious.css({'z-index' : '0', 'width' : '1000px'});
		$slideNext.css({'z-index' : '0', 'width' : '1000px'});
			
		//Push next slide to the right
		$slideNext.hide().animate({"left": "-=1000px"});
			
		//Scroll current and next slide to left
		$currSlide.animate({"left": "+=1000px"}, 2500);
		$slideNext.animate({"left": "+=1000px"}, 2500).show();
	
		//Return slide to 0 and call update once animation complete
		$currSlide.hide(100).animate({"left": "0"}, {complete: function() {
			reassignRightVariables();
		}
		});			
		return false;
/*		if($('#sliderContent1').is(':visible')){
			
			//Change z-index so current slide is on top
			$('#sliderContent1').css({'z-index' : '2', 'width' : '1000px'});
			$('#sliderContent3').css({'z-index' : '0', 'width' : '800px'});
			
			//Push next slide to the right
			$('#sliderContent3').hide().animate({"left": "-=900px"});
			
			//Scroll current and next slide to left
		    $('#sliderContent1').animate({"left": "+=900px"}, 2500);
			$('#sliderContent3').animate({"left": "+=900px"}, 2500).show();

			//Return slide to 0
		    $('#sliderContent1').hide(100).animate({"left": "0"});			
			
		}else if($('#sliderContent2').is(':visible')){

			//Change z-index so current slide is on top
			$('#sliderContent2').css({'z-index' : '2', 'width' : '1000px'});
			$('#sliderContent1').css({'z-index' : '0', 'width' : '800px'});
			
			//Push next slide to the right
		    $('#sliderContent1').hide().animate({"left": "-=900px"});

			//Scroll current and next slide to left
		    $('#sliderContent2').animate({"left": "+=900px"}, 2500);
			$('#sliderContent1').animate({"left": "+=900px"}, 2500).show();

			//Return slide to 0
		    $('#sliderContent2').hide(100).animate({"left": "0"});
		}else if($('#sliderContent3').is(':visible')){
			//Change z-index so current slide is on top
			$('#sliderContent3').css({'z-index' : '2', 'width' : '1000px'});
			$('#sliderContent2').css({'z-index' : '0', 'width' : '800px'});
			
			//Push next slide to the right
		    $('#sliderContent2').hide().animate({"left": "-=900px"});

			//Scroll current and next slide to left
		    $('#sliderContent3').animate({"left": "+=900px"}, 2500);
			$('#sliderContent2').animate({"left": "+=900px"}, 2500).show();

			//Return slide to 0
		    $('#sliderContent3').hide(100).animate({"left": "0"});
		}
		*/
	  }
	
	  //Update the variables if scrolling left
	  function reassignVariables(){
		$currSlide.css({'z-index' : '0'});

		//Assign new values to variables
		$currSlide = $slidePrevious;
		if($currSlide.prev(".bigSlide").length == 0){
			$slidePrevious = $('#slideEnd');
		}else{
			$slidePrevious = $currSlide.prev(".bigSlide");
		}
		if($currSlide.next(".bigSlide").length == 0){
			$slideNext = $('#slideStart');
		}else{
			$slideNext = $currSlide.next(".bigSlide");
		}
	  }

	  //Update the variables if scrolling left
	  function reassignRightVariables(){
		$currSlide.css({'z-index' : '0'});

		//Assign new values to variables
		$currSlide = $slideNext;
		if($currSlide.prev(".bigSlide").length == 0){
			$slidePrevious = $('#slideEnd');
		}else{
			$slidePrevious = $currSlide.prev(".bigSlide");
		}
		if($currSlide.next(".bigSlide").length == 0){
			$slideNext = $('#slideStart');
		}else{
			$slideNext = $currSlide.next(".bigSlide");
		}
	  }

	// Call this function to stop the automatic slideshow
	/*function abortTimer() { 
	  clearInterval(tid);
	}*/
	
	//Code for homepage small slider
	//Define variables
	var $currentCircle = $('#firstCircle');
	$currentCircle.addClass("controlCircleActive");	
	var $currentSlide = $('#firstSlide');
	var $prevSlide;
	var $nextSlide;
	
	//Check if animation is at the beginning of slides
	if($currentSlide.prev(".slide").length == 0){
		$prevSlide = $('#lastSlide');
	}else{
		$prevSlide = $currentSlide.prev(".slide");
	}

	//Check if animation is at the end of slides
	if($currentSlide.next(".slide").length == 0){
		$nextSlide = $('#firstSlide');
	}else{
		$nextSlide = $currentSlide.next(".slide");
	}
	
	$('#scrollLeftSm').click(function() {
		//Do not execute function if animation in process
		if ($('.slide:animated').length) {
			return false;
		}

		//Code to change the circles with image
		if($currentCircle.prev(".controlCircle").length == 0){
		  $currentCircle = $('#lastCircle');
		}else{		
		  $currentCircle = $currentCircle.prev(".controlCircle");
		}
		$("div").removeClass("controlCircleActive");
		$currentCircle.addClass("controlCircleActive");

		//Change z-index so current slide is on top
		$currentSlide.css({'z-index' : '2'});
		$prevSlide.css({'z-index' : '0'});
		$nextSlide.css({'z-index' : '0'});
			
		//Push next slide to the right
		$prevSlide.hide().animate({"left": "+=280px"});
			
		//Scroll current and next slide to left
		$currentSlide.animate({"left": "-=280px"}, 2000);
		$prevSlide.animate({"left": "-=280px"}, 2000).show();
	
		//Return slide to 0 and call update once animation complete
		$currentSlide.hide(100).animate({"left": "0"}, {complete: function() {
			updateVariables();
			}
		});			
		  return false;
	  });

	$('#scrollRightSm').click(function() {		
		//Do not execute function if animation in process
		if ($('.slide:animated').length) {
			return false;
		}

		//Code to change the circles with image
		if($currentCircle.next(".controlCircle").length == 0){
		  $currentCircle = $('#firstCircle');
		}else{		
		  $currentCircle = $currentCircle.next(".controlCircle");
		}
		$("div").removeClass("controlCircleActive");
		$currentCircle.addClass("controlCircleActive");

		//Change z-index so current slide is on top
		$currentSlide.css({'z-index' : '2'});
		$prevSlide.css({'z-index' : '0'});
		$nextSlide.css({'z-index' : '0'});
			
		//Push next slide to the right
		$nextSlide.hide().animate({"left": "-=280px"});
			
		//Scroll current and next slide to left
		$currentSlide.animate({"left": "+=280px"}, 2000);
		$nextSlide.animate({"left": "+=280px"}, 2000).show();
	
		//Return slide to 0 and call update once animation complete
		$currentSlide.hide(100).animate({"left": "0"}, {complete: function() {
			updateRightVariables();
			}
		});			
		  return false;
	  });
	
	  //Update the variables if scrolling left
	  function updateVariables(){
		$currentSlide.css({'z-index' : '0'});

		//Assign new values to variables
		$currentSlide = $prevSlide;
		if($currentSlide.prev(".slide").length == 0){
			$prevSlide = $('#lastSlide');
		}else{
			$prevSlide = $currentSlide.prev(".slide");
		}
		if($currentSlide.next(".slide").length == 0){
			$nextSlide = $('#firstSlide');
		}else{
			$nextSlide = $currentSlide.next(".slide");
		}
	  }
	  
	  //Update the variables if scrolling right
	  function updateRightVariables(){
		$currentSlide.css({'z-index' : '0'});

		//Assign new values to variables
		$currentSlide = $nextSlide;
		if($currentSlide.prev(".slide").length == 0){
			$prevSlide = $('#lastSlide');
		}else{
			$prevSlide = $currentSlide.prev(".slide");
		}
		if($currentSlide.next(".slide").length == 0){
			$nextSlide = $('#firstSlide');
		}else{
			$nextSlide = $currentSlide.next(".slide");
		}
	  }
			
});

