// JavaScript Document
$(document).ready(function() { 
	adjustHeight();
	adjustIconSlider();
	adjustImageSlider();
	//adjustEventSlider();
	galleryTitles();
	
	$(".gallery-content a").each(function(i){
		$(this).attr("class",'colorbox');
		$(this).attr("rel",'portfolio');
	});
	
	$(".ngg-widget a").each(function(i){
		$(this).attr("href", url+"/gallery");
		$(this).attr("rel", url+"/gallery");
	});
	
	$("a.colorbox").each(function(i){
		var src = $(this).find("img").attr("src");
		//alert(src);
		$(this).attr("href", src);
	});
	
	$(".ngg-widget a").each(function(i){
		$(this).attr("href", url+"/gallery");
		$(this).attr("rel", "");
	});
		
		$("a[rel='portfolio']").colorbox({
		maxWidth:"70%",
		maxHeight:"88%",
		transition:"fade",
		opacity:0.8,
		title:true,
		slideshow: false,
		
		});
		
				
		$("#searchsubmit").each(function(i){
			$(this).attr("value",''); //alert("a");
		});
		
		$("#todayWidget").each(function(i){
			//$(this).css({"color":"#fff"});
		})	
});


function adjustHeight(){
	var containerHeight = $(".container").height();
	var contentHeight = containerHeight;
	//$(".content").css({"height": contentHeight+"px"});
	var content = $(".content").height();
	var sidebarHeight=$(".sidebar").height();
	//alert(content);
	//alert(sidebarHeight);
	
	if(sidebarHeight > content ) {
		$(".content").css({"height": sidebarHeight-5+"px"}); //alert("sidebar"+$(".sidebar").height());
		$(".page-content").css({"height": sidebarHeight-35+"px"});//alert("page-height"+$(".page-content").height());
		$(".search-results").css({"height": sidebarHeight-35+"px"});
		$(".featured-news-content").css({"height": sidebarHeight-35+"px"});
		$(".search-results").css({"height":sidebarHeight-35+"px"}); //alert("sdf");
		$(".news-press").css({"height":sidebarHeight-35+"px"});
		$(".post-content").css({"height": sidebarHeight-340+"px"});//alert("page-height"+$(".page-content").height());
		$(".news-content").css({"height": sidebarHeight-498+"px"});//alert("page-height"+$(".page-content").height());

	}
	else if(sidebarHeight < content)
	{
		$(".sidebar").css({"height": content+"px"});//alert("sidebar"+$(".sidebar").height());
		sidebarHeight=$(".sidebar").height();
		$(".page-content").css({"height": content-35+"px"}); //alert("page-height"+$(".page-content").height());
		$(".search-results").css({"height": sidebarHeight-35+"px"});
		$(".featured-news-content").css({"height": sidebarHeight-35+"px"});
		$(".search-results").css({"height":sidebarHeight-35+"px"}); //alert("sdf");
		$(".news-press").css({"height":sidebarHeight-35+"px"});
		
	}//alert("sidebar"+sidebarHeight);
	//alert("contetn"+pageHeight); 
	//alert(sidebarHeigh);
		
}

function adjustIconSlider() {
	var w = 151;
	//var b = 2 * 2;
	//var m = 2 * 7;
	var s = $(".icon-slider li.cat-item ").size();
	var sliderWidth = s *w// + b+m);
	$(".icon-slider").css({"width" : sliderWidth + "px"});
	
	var current = 0;
	var limit = s-5;	
	//alert(sliderWidth);
	
	$(".slider-next").click(function(){
			
		if(current < limit) {
			current ++;
			var posLeft = 0 - (current * w);
			$(".icon-slider").stop(true,true).animate({"left" : posLeft + "px"}, 600);	
			//$(".icon-slider").css({"left" : posLeft + "px"});
		}
	});
	
	$(".slider-prev").click(function(){
		if(current > 0) {
			current --;
			var posLeft = 0 - (current * w);
			$(".icon-slider").stop(true,true).animate({"left" : posLeft + "px"}, 600);	
		}
	});
}

function adjustImageSlider() {
	var w = 81;
	//var b = 2 * 2;
	//var m = 2 * 7;
	var s = $(".image-slider div ul li").size();
	var sliderWidth = s *w// + b+m);
	$(".image-slider div").css({"width" : sliderWidth + "px"});
	//$(".wp_bannerize_social").css({"width" : sliderWidth+20 + "px"});	
	var current = 0;
	var limit = s-8;	
	//alert(sliderWidth);
	
	$(".gallery-slider-next").click(function(){
			
		if(current < limit) {
			current ++;
			var posLeft = 0 - (current * w);
			$(".image-slider div").stop(true,true).animate({"left" : posLeft + "px"}, 600);	
			//$(".icon-slider").css({"left" : posLeft + "px"});
		}
	});
	
	$(".gallery-slider-prev").click(function(){
		if(current > 0) {
			current --;
			var posLeft = 0 - (current * w);
			$(".image-slider div").stop(true,true).animate({"left" : posLeft + "px"}, 600);	
		}
	});
}

function galleryTitles() {
	$("a.colorbox").each(function(){
		var thisTitle = $(this).find("img").attr("title");
		//alert(thisTitle);
		$(this).attr("title", thisTitle);	
	});	
}
