//////////////////////////////////////////////////////
//
//	The purpose of this file is to
//	apply a hover class on mouseover
//	on the <li> elements in the nav.
//	This is because IE doesn't put
//	the pseudo class :hover on <li> elements
//
//	This is code that uses the
//	jquery javascript library (http://jquery.com/)
//
//////////////////////////////////////////////////////
$(window).load(function() {
	if (document.all&&document.getElementById) {
		// this is needed for the IE 6 pseudo hover class bug
		$(".navtop li").hover(function () {
			$(this).addClass("hover");
		},function () {
			$(this).removeClass("hover");
		});
	} else {
		// this is need for safari when nav covers flash
		$(".navtop li ul").hover(function () {
			$(this).addClass("redraw");
		},function () {
			$(this).removeClass("redraw");
		});
	}
	$("img#left").css('opacity', '0.5');
	var image_count = $('div#carousel img').length;
	if(image_count < 7) {
		$('img#right').css('opacity', '0.5');
	}
	var max_left = (image_count - 6) * -163;
	$("img#left").click(function() {
		var left = parseInt($('div#carousel').css('left').replace('px', ''));
		if(left >= 0) {
			return false;
		}
		var shift_left = left + 163;
		if(shift_left >= 0) {
			$("img#left").css('opacity', '0.5');
		}
		$('div#carousel').animate({ left: shift_left + 'px' }, 500);
		$('img#right').css('opacity', '1.0');
	});
	$("img#right").click(function() {
		var left = parseInt($('div#carousel').css('left').replace('px', ''));
		if(left <= max_left) {
			return false;
		}
		var shift_left = left - 163;
		if(shift_left <= max_left) {
			$('img#right').css('opacity', '0.5');
		}	
		$("div#carousel").animate({ left: shift_left + 'px' }, 500);
		$("img#left").css('opacity', '1.0');
	});

	$("div#image_set img").click(function() {
		replace_content(this.id)
	});
	$('div.banner_photos img').click(function() {
		replace_main(this.src);
	});
	if($('input#current_content').length > 0) {
		var first_div = $('div#image_set img:first').attr('id');
		replace_content(first_div);
	}
        if($('#carousel').length > 0)
        {
         
         if (window.location.hostname.indexOf("cms") < 0){
	
	      $('#carousel').width('5000px');
          }
        }
});

var replace_main = function(image_src) {
	image_src = image_src.replace('thumb', 'main');
	var image_html = '<img src="' + image_src + '" />';
	$('div#main_image').animate({ opacity: '0.0' }, 500, 'linear', function() {
		$('div#main_image').html(image_html);
		$('div#main_image').animate({ opacity: '1.0' }, 500);
	});
}

var replace_content = function(region) {
	var new_region = region.replace('slider', 'sub');
	var old_region = $("input#current_content").attr('value');
	$('div#' + old_region).css('display', 'none');
	$('div#image_set img').css('opacity', '0.75');
	$('div#image_set img#' + region).css('opacity', '1.0');
	$('input#current_content').attr('value', new_region);
	$('div#' + new_region).css('display', '');
	var src = $('div#' + new_region + ' div.banner_photos img:first').attr('src').replace('thumb', 'main');
	var image_html = '<img src="' + src + '" />';
	$('div#main_image').animate({ opacity: '0.0' }, 500, 'linear', function() {
		$('div#main_image').html(image_html);
		$('div#main_image').animate({ opacity: '1.0' }, 500);
	});
}
