jQuery(document).ready(function(){
	
	menuWidthAdjust();
	
	//contentHeightAdjust();
	
	homePaddings();
	
	hsliderAddClass();
	
	galleryThumbSlider();
	
	setInterval( "slideSwitch()", 5000 );
	
	galleryImgID();
	
	$(function () {
		
		$("a[rel='colorbox']").colorbox();
		
	})
	
});

function menuWidthAdjust() {
	
	var menuWidth = jQuery("div.menu").width();
	var itemsCount = jQuery("div.menu ul.menu li").size();
	var itemsBorders = 4*5;
	var itemWidth = (menuWidth-itemsBorders) / itemsCount;
	
	//jQuery("div.menu ul.menu_list li a").width(itemWidth);
	
	jQuery("div.menu ul.menu li").each(function(){
		
		var eachItemWidth = jQuery(this).width();
		var itemPaddingTotal = itemWidth - eachItemWidth;
		var itemPadding = itemPaddingTotal / 2;
		
		jQuery(this).find('a').css('padding-right',itemPadding);
		jQuery(this).find('a').css('padding-left',itemPadding);
		
	});
	
}

function contentHeightAdjust() {
	
	var windowHeight = jQuery(window).height();
	var headerHeight = jQuery(".header").height();
	var footerHeight = jQuery(".footer").height() + jQuery(".footer").outerHeight();
	var wrapperHeight = windowHeight - headerHeight - 4;
	var contentHeight = wrapperHeight - footerHeight;
	
	jQuery(".wrapper").css("min-height",wrapperHeight);
	jQuery(".content_home").height(contentHeight);
	
	
}

function homePaddings() {
	
	var wrapperHeight = jQuery(".wrapper").height() ;
	var footerHeight = jQuery(".footer").height() + jQuery(".footer").outerHeight();
	var contentHeight = wrapperHeight - footerHeight;
	
	var marginValue = ((contentHeight - 312) / 2) + "px";
	
	jQuery(".wp_bannerize_home_banner").css("margin-top", marginValue);
}

function hsliderAddClass() {
	
	 var position = 0;
     var left_pos = 0;
     var banner_width = 0;
     var j = 0;
     var bannerClass = ".wp_bannerize_home_banner ul li";
  
     jQuery(bannerClass).each(function() {
         jQuery(this).addClass("img_" + j);
         j++;
     });
}

function slideSwitch() 
{ 

    var $active = jQuery('.wp_bannerize_home_banner ul .active');

    if ( $active.length == 0 ) $active = jQuery('.wp_bannerize_home_banner ul li:last-child');

    var $next =  $active.next().length ? $active.next()
        : jQuery('.wp_bannerize_home_banner ul li:first-child');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, 
        	function() 
        	{
	            $active.removeClass('active last-active');
	        });
}

function galleryImgID() {
	
	var k = 0;
	
	jQuery(".gallery_large_image img").each(function() {
		
		jQuery(this).addClass("img_" + k);
        k++;
		
	});
	
	jQuery(".thumbs_slider ul.slider li.slide").each(function() {
		
		jQuery(this).addClass("img_" + k);
		k++;
		
	});
	
}

function changeImage(imgcaption, img_id) 
{
		jQuery(".gallery_large_image img").fadeOut("slow");
		jQuery(".gallery_large_image img.img_"+img_id).fadeIn("slow");

		var caption = "<span>"+imgcaption+"</span>";
		jQuery(".image_caption span").remove();
		jQuery(".image_caption").append(caption);
}
	
function galleryThumbSlider() {
	
	var n = jQuery("ul.slider li").size();
	var w = n * 78;
	var current = 0;
	
	jQuery("ul.slider").width(w);
	
	jQuery(".left_button").click(function() {
		
		if(current > 0) {
			
			current --;
			var to_left = 0 - (current * (78*6)) + "px";
			jQuery("ul.slider").stop(true, false).animate({"left": to_left});
			
		}
		
	});

	jQuery(".right_button").click(function() {
			
			if(current < ((n / 6)- 1)) {
				
				current++;
				var to_left = 0 - (current*(78*6)) + "px";
                jQuery("ul.slider").stop(true, false).animate({"left": to_left});
				
			}
		});
}


