var isMoving = false;

$(document).ready(function() {
	
	$('.rotating-item').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
	
	$('.rotating-item').click(function() {
		var displayvalue = $(this).children("a").attr("href");
		
		window.open(displayvalue, "_top");
	})
	
	$('#logo h1').click(function() {
		window.open("/", "_top");
	});
	
	
	$('.solutions').click(function() {
		
		$(this).toggleClass('current').removeClass('fadeout');
		
		//alert(this.className);
		
		if (this.className.indexOf('current') == -1) {
			
			$('.products').removeClass('current').removeClass('fadeout');
			$('.support').removeClass('current').removeClass('fadeout');
		} else {
			$('.products').removeClass('current').addClass('fadeout');
			$('.support').removeClass('current').addClass('fadeout');
		}
	
		
		//$('.products').removeClass('current').addClass('fadeout');
		//$('.support').removeClass('current').addClass('fadeout');
		
		$('.solutions-content').slideToggle("fast");
		
		$('.products-content').slideUp("fast");
		$('.support-content').slideUp("fast");
	});
	
	$('.products').click(function() {
		
		$(this).toggleClass('current').removeClass('fadeout');
		
		
		if (this.className.indexOf('current') == -1) {
			
			$('.support').removeClass('current').removeClass('fadeout');
			$('.solutions').removeClass('current').removeClass('fadeout');
		} else {
			$('.support').removeClass('current').addClass('fadeout');
			$('.solutions').removeClass('current').addClass('fadeout');
		}
		
		$('.products-content').slideToggle("fast");
		
		$('.solutions-content').slideUp("fast");
		$('.support-content').slideUp("fast");
	});
	
	$('.support').click(function() {
		
		$(this).toggleClass('current').removeClass('fadeout');
		
		if (this.className.indexOf('current') == -1) {
			
			$('.products').removeClass('current').removeClass('fadeout');
			$('.solutions').removeClass('current').removeClass('fadeout');
		} else {
			$('.products').removeClass('current').addClass('fadeout');
			$('.solutions').removeClass('current').addClass('fadeout');
		}
		
		$('.support-content').slideToggle("fast");
		
		$('.products-content').slideUp("fast");
		$('.solutions-content').slideUp("fast");
	});

	
	$('#menu ul li img').hover(function() {
		$(this).addClass('border');
	}, function() {
		$(this).removeClass('border');	
	});
	
	$('.arrow-prev').hover(function() {
		$(this).addClass('arrow-prev-hover');
	}, function() {
		$(this).removeClass('arrow-prev-hover');
	});
	
	$('.arrow-next').hover(function() {
		$(this).addClass('arrow-next-hover');
	}, function() {
		$(this).removeClass('arrow-next-hover');
	});
	
	
	
	$('.arrow-prev').click(function() {
		if (isMoving == false) {
			isMoving = true;
			
			var scrollwidth = $('#rotating-items').css("left");
			
			var num = parseFloat(scrollwidth, 10);
			
			var newwidth = num + 174;
			var unit = 'px';
        	
			if(newwidth > -1) {
				
			} else {
				//$('#rotating-items').css('left', newwidth + unit);
				$('#rotating-items').animate({left: newwidth}, 200);
			}
			
			window.setTimeout(function(){isMoving = false},500);
			//$('#rotating-items').css('left', newwidth + unit);
		} else {
			
		}
	});
	
	$('.arrow-next').click(function() {
		//alert(isMoving);
		if (isMoving == false) {
			isMoving = true;
			//alert($isMoving);
			
			var scrollwidth = $('#rotating-items').css("left");
			
			var num = parseFloat(scrollwidth, 10);
			
			var newwidth = num - 174;
			var unit = 'px';
			
			
			//if(newwidth < -349) {
			if(newwidth < -697) {
				
			} else {
				$('#rotating-items').animate({left: newwidth}, 200)
			}
			window.setTimeout(function(){isMoving = false},200);
			//alert(isMoving);
			//isMoving = false;

		} else {
			
		}

		
	});
	
	$('#arrow-feature').click(function() {
		
		$('#feature-content-products').slideToggle("slow",swapUpDownArrow('arrow-feature'));
		
	});
	
	$('#arrow-system-req').click(function() {
		
		$('#system-req-content-products').slideToggle("slow",swapUpDownArrow('arrow-system-req'));
		
	});
	
	function swapUpDownArrow(elem) {
		/*
		alert("hello");
		alert(document.getElementById('arrow-feature').src);
		*/
		if(document.getElementById(elem).src=="http://boss-solutions.com/images/arrow-up.gif") {
			document.getElementById(elem).src="/images/arrow-down.gif";
		} else {
			document.getElementById(elem).src="/images/arrow-up.gif";
		}
	};
	
	
	$('#side-nav-utility dt').hover(function() {
		var targetDD=this;
		while (targetDD.tagName!='DD' && targetDD.nextSibling)
		{
			targetDD=targetDD.nextSibling;
			//alert(targetDD);
		}
		if(this.className=="first") {
			$(this).addClass('first-on');
		} else {
			$(this).addClass('on');
		}
		$(targetDD).addClass('on');
		//alert(this.className);
		if(this.className=="next-to-last on") {
			$(targetDD.nextSibling).addClass('last-on');
			//targetDD.previousSibling.style.border="1px #ff0000 solid";
		}
		this.childNodes[1].src="/images/arrow-utility-right-on.gif";
	}, function() {
		var targetDD=this;
		while (targetDD.tagName!='DD' && targetDD.nextSibling)
		{
			targetDD=targetDD.nextSibling;
		}
		if(this.className=="first" || this.className=="first first-on") {
			$(this).removeClass('first-on');
		} else {
			$(this).removeClass('on');
		}
		$(targetDD).removeClass('on');
		//alert(this.className);
		if(this.className=="next-to-last") {
			$(targetDD.nextSibling).removeClass('last-on');
			//targetDD.style.border="1px #000000 solid";
		}
		this.childNodes[1].src="/images/arrow-utility-right-off.gif";
	});
	//We will need to uncomment the following line when we push the search changes
	//document.getElementById('q').blur();

	var checkSearchInterval = 0;
	$('#q').focus(function() {
		//alert(document.getElementById("q").value.length);
		//checkSearchInterval = setInterval(checkSearch, 500);
		//document.getElementById('custom-search').style.backgroundImage="url(/images/search-bg-on.jpg)";
		document.getElementById('custom-search').style.backgroundImage="url(/images/search-bar-on.jpg)";
		document.getElementById("q").value="";
	});						  
	
	$('#q').blur(function() {
		//clearInterval(checkSearchInterval);
		//$('#search-dropdown-wrapper:visible').slideToggle("fast");
		document.getElementById('custom-search').style.backgroundImage="url(/images/search-bar-off.jpg)";
		//document.getElementById('q').value="Problem? Search here to instantly find your solution.";
	});	
	
	$('#q').mouseout(function() {
	});
	
	$('#q').mouseover(function() {	
	});

	
	/*
	$('#custom-search').mouseout(function() {
		var inputValue = document.getElementById('q').value;
		if(inputValue != ''){
			//alert("WHY");
			document.getElementById('search-dropdown-wrapper').style.display="none";
		}
	});
	*/
	/*
	$('#search-dropdown-wrapper').mouseover(function() {
		this.style.display="none";
	});
	
	
	$('#custom-search').mouseover(function() {
		var inputValue = document.getElementById('q').value;
		if(inputValue != ''){
			//document.getElementById('search-dropdown-wrapper').style.display="block";
		}
	});
	*/
	
	$('#search-button').hover(function() {
		//this.style.backgroundColor="#CCCCCC";
		this.src="/images/search-button-over.gif";
		this.style.cursor="pointer";
	}, function() {
		//this.style.backgroundColor="#FFFFFF";
		this.src="/images/search-button-off.gif";
	});
	
	$('#search-dropdown-footer').click(function() {
		//clearInterval(checkSearchInterval);
		//document.getElementById('custom-search').style.backgroundImage="url(/images/search-bg.jpg)";
		document.getElementById('custom-search').style.backgroundImage="url(/images/searchbox-off.gif)";
	});
	
	$('.search-dropdown-item-wrapper').hover(function() {
		//this.style.backgroundColor="#CCCCCC";
		this.style.backgroundImage="url(/images/search-dropdown-bg-on.png)";
		this.style.cursor="pointer";
	}, function() {
		//this.style.backgroundColor="#FFFFFF";
		this.style.backgroundImage="url(/images/search-dropdown-bg.png)";
	});
	
	/*
	$('.search-dropdown-item-wrapper').hover(function() {
		this.style.backgroundColor="#999999";
		alert("click");
	});
	
	
	function checkSearch()
	{
 		 //alert("wohoo");
		 if(document.getElementById("q").value.length > 0)
		 {
		 	$('#search-dropdown-wrapper:hidden').slideToggle("fast");
		 } else
		 {
			//alert(document.getElementById("q").value.length);
			$('#search-dropdown-wrapper:visible').slideToggle("fast");
		 }
	}
		*/
	/* LIGHTBOX EFECT */
	
	
	
	/*
	$('#side-nav-utility dd').hover(function() {
		var targetDT=this;
		while (targetDT.tagName!='DT' && targetDT.previousSibling)
		{
			targetDT=targetDT.previousSibling;
		}
		targetDT.childNodes[1].src="/images/arrow-utility-right-on.gif";
		if(this.className=="first") {
			$(targetDT).addClass('first-on');
		} else {
			$(targetDT).addClass('on');
		}
		$(this).addClass('on');
		//alert(this.className);
		if(this.className=="last on") {
			//alert(this.nextSibling.tagName);
			$(this.previousSibling).addClass('on');
			$(this).addClass('last-on');
		}
		if(this.className=="next-to-last on") {
			//alert(this.nextSibling.tagName);
			$(this).addClass('on');
			$(this.nextSibling).addClass('last-on');
		}
	}, function() {
		var targetDT=this;
		while (targetDT.tagName!='DT' && targetDT.previousSibling)
		{
			targetDT=targetDT.previousSibling;
		}
		targetDT.childNodes[1].src="/images/arrow-utility-right-off.gif";
		if(this.className=="first" || this.className=="first on") {
			$(targetDT).removeClass('first-on');
		} else {
			$(targetDT).removeClass('on');
		}
		$(this).removeClass('on');
		//alert(this.className);
		if(this.className=="last" || this.className=="last last-on") {
			//alert(this.nextSibling.tagName);
			$(this.previousSibling).removeClass('on');
			$(this).removeClass('last-on');
		}
		if(this.className=="next-to-last") {
			//alert(this.nextSibling.tagName);
			$(this).removeClass('on');
			$(this.nextSibling).removeClass('last-on');
		}
	});
	*/
	
	
	
});