function smartRollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");

		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("_off."))
			{
				images[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
				}
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
				}
			}
		}
	}
}

if(window.addEventListener) {
	window.addEventListener("load", smartRollover, false);
}
else if(window.attachEvent) {
	window.attachEvent("onload", smartRollover);
}

$(function(){
	$('#pageTop a, .ancLink').click(function() {  
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {  
            var $target = jQuery(this.hash);  
            $target = $target.length && $target || jQuery('[name=' + this.hash.slice(1) +']');  
            if ($target.length) {  
                var targetOffset = $target.offset().top;  
                jQuery('html,body').animate({ scrollTop: targetOffset }, 1500, 'easeOutQuart');  
                return false;  
            }  
        }  
    });
});

// review
function review(){
	setTimeout(function(){
		reviewWindow();
		if($('#photo_select li').size() >= 1) {
			$('#photo_select li a').click(function(){
				return false;
			});
		}
		
		if($('#photo_select li').size() >= 2) {
			actLi = $(this);
			$('#photo_select li a').click(function(){
				$('#photo_select .act').removeClass('act');
				$(this).parent('li').addClass('act');
				
				actPhoto = $(this).attr('href');
				targetPhoto = $('#movie_photos #photo '+ actPhoto).attr('class');
				if(targetPhoto != 'act') {
					$('#movie_photos #photo .act').fadeOut(400,function(){
						$(this).removeClass('act');
					});
					$(actPhoto).fadeIn(400,function(){
						$(this).addClass('act');
					});
					return false;
				} else {
					return false;
				}
			});
		}
	},100);
}

function reviewWindow(){
	setTimeout(function(){
		if($('#movie_photos .act').size() != 0) {
			imgH = $('#movie_photos .act img').height();
			$('#movie_photos #photo').css({height:imgH});
		} else {
			$('#movie_photos').remove();
		}
	},200);
}

function reviewSMT(){
	setTimeout (function(){
		if($('#movie_photos .act img').width() != $('#movie_photos').width()) {
			$('#movie_photos .act img').width($('#movie_photos').width());
		}
	},150);
}

function topCarousel(){
	imgH = $('.carouselBox img').height();
	boxH = $('.carouselBox:visible').height();
	if(imgH == boxH){
		if($('.slides_control').height() != imgH) {
			$('.slides_control').height(imgH);
		}
	} else {
		if($('.slides_control').height() != boxH) {
			$('.slides_control').height(boxH);
		}
	}
}

function carousel(){
	$('#mainCarousel').slides({
		slideEasing: "easeOutQuad",
		slideSpeed: 800
	});
	setTimeout(topCarousel,850);
}



function topJS(){
	$('.carouselBox:first').css({display:'block'});
	topCarousel();
	carouselContent = $('.slides_container').html();
	if($('#carousel2').size() != 0) {
		carousel();
	}
	
	$('#top #btn_next,#top #btn_prev').live('click',function(){
		setTimeout(topCarousel,850);
	}); 
}




var resizeTimer = null;
$(window).bind('resize', function() {
	if($('#movie_photos li').size() != 0) {
		if (resizeTimer) clearTimeout(resizeTimer);
		resizeTimer = setTimeout(reviewWindow, 100);
	}
	
	if($('#carousel2').size() != 0) {
		imgH2 = $('.carouselBox img').height();
		boxH2 = $('.carouselBox:visible').height();
		if (resizeTimer){
			clearTimeout(resizeTimer);
			if(imgH2 != boxH2){
				$('.slides_container').empty().append(carouselContent);
				carousel();
			}
		}
		resizeTimer = setTimeout(topCarousel, 200);
	}
});
