$(document).ready(function() {
	
	var idTimeout;
	var imgs = $(".sliderPhotos .photoItem");
	var count = imgs.size();	
	var curPhoto = count;
	var li = $(".rotator li");
	var items = $(".bot_prt .slideItem");
	function initSlideShow(){
		clearInterval(idTimeout);
		$(".sliderPhotos .photoItem").stop();
		runSlideshow();
		idTimeout = setInterval(runSlideshow, 4000);
	}
	function runSlideshow(){
		if(curPhoto < count - 1 && curPhoto > -1){
			curPhoto++;
		}
		else{
			curPhoto = 0;	
		}
		
		li.removeClass("active");	
		li.eq(curPhoto).addClass("active");
		
		$(".sliderPhotos .active").animate({
			opacity: 0
		}, 1000, function() {
			$(".sliderPhotos .active").removeClass("active");
		});
		
		$(".sliderPhotos .photoItem").eq(curPhoto).animate({
			opacity: 1
		}, 1000, function() {
			$(this).addClass("active");
			$(this).css("opacity", 0);
			
			$(this).animate({
				opacity: 1
			}, 1000, function() {
				
			});
			
		});
	}
	function initClicks(){
		$(".rotator li").each(function(index){
			$(this).click(function(){
				if($(this).index() == 0){
					curPhoto = count;
				}
				else{
					curPhoto = index - 1;
				}
				initSlideShow();
			});
		});
		/*
		$(".btn_sl_prev").click(function(){
			if(curPhoto <= 0){
				curPhoto = li.size()-2;	
			}
			else{
				curPhoto-=2;
			}
			initSlideShow();
		});
		$(".btn_sl_next").click(function(){
			initSlideShow();
		});
		*/
	}
	function initSubMenu(){
		$(".menuItem").each(function(){
			$(this).parents("td").eq(0).mouseover(function(){
				$(this).addClass("active");
			});
			$(this).parents("td").eq(0).mouseout(function(){
				$(this).removeClass("active");
			});
		});		
	}
	
	initSlideShow();
	initClicks();
	initSubMenu();
	
});
function showHidePopup(lnk){
	var par = $(lnk).parents(".popup_row").eq(0);	
	
	if(par.hasClass("active")){
		par.removeClass("active");
	}
	else{
		par.addClass("active");
	}
}
function hidePopup(){
	var par = $(".popup_row").eq(0);
	
	if(par.hasClass("active")){
		par.removeClass("active");
	}
}
