/*
---------------------------------------------------------------------------------
JAVASCRIPT SURGEWORKS WEBSITE - V1.0 - 20/03/2008
---------------------------------------------------------------------------------

RENATO CARVALHO
---------------------------------------------------------------------------------*/


/* TICKBOX CSS EXPRESSIONS - TRICK TO VALIDATE THICKBOX.CSS */
function fixHeight(scrollHeight, offsetHeight) {
   return (scrollHeight > offsetHeight ? scrollHeight : offsetHeight + 'px');
}

function fixMarginTop(offsetHeight,documentElement,scrollTop) {
	return (0 - parseInt(offsetHeight / 2) + (TBWindowMargin = documentElement && documentElement.scrollTop || scrollTop) + 'px');	
}


/*
--------------------------------------------------------------------
SERVICES
--------------------------------------------------------------------
*/
var Services = {
	init : function() {
		//INITIAL SETUP
		$("div.serviceContent:not(:first)").hide();
		$("div.serviceContent:first").show();
		$("div#servicesWrap div:first").addClass("current");
		$("div#services ul li a:first").addClass("current");
		
		$("div#services ul li a").bind("click", function(){
			$("div#services ul li.current").removeClass("current");
			$("div#servicesWrap > div").removeClass("current").hide();
			
			$("div#servicesWrap div "+ $(this).attr("href")).addClass("current");	
			$("div "+$(this).attr("href")).fadeIn();
			$($(this).parent()).addClass("current");
	
			//Equalize Columns
			//$("#aboutUs, #services").equalizeCols();
			return false;
		});
	}
};



/*
--------------------------------------------------------------------
NEWS SLIDESHOW
--------------------------------------------------------------------
*/
var News = {
	total : Object,
	current : null,
	timeout : 6000,
	timeOutNews : null,
	
	init : function() {
		//CONFIGURATION
		elementPath = "#ticker";
		currentNews = 0;
		totalNews = $(elementPath).children().length;
		
		//INIT ELEMENTS
		$(elementPath).children().hide();
		$(elementPath).children(":first").show();
		$(elementPath).children(":first").addClass("current");
		
		timeOutNews = setTimeout("News.slideShow()", this.timeout);
		
		$(elementPath).hover(function(){ //mouse over
			if(timeOutNews) {clearTimeout(timeOutNews);}
		},function(){ //mouse out
			timeOutNews = setTimeout("News.slideShow()", News.timeout/2);
		});
	},
	goToNews : function(positionNews) {
		//reset news
		$(elementPath).children(".current").removeClass("current").hide();
		//show news
		$(elementPath).children().eq(positionNews).slideDown("slow").addClass("current");
	},
	nextNews : function() {
		if(currentNews < totalNews-1) {
			currentBanner++;
			News.goToNews(currentNews);
		}
		if(timeOutNews) {clearTimeout(timeOutNews);}
		return false;
	},
	prevNews : function() {
		if(currentNews > 0) {
			currentNews--;
			News.goToNews(currentNews);
		}
		if(timeOutNews) {clearTimeout(timeOutNews);}
		return false;
	},
	slideShow :	function() {
		if(currentNews < totalNews-1) {
			currentNews++;
		} else {
			currentNews = 0;
		}
		News.goToNews(currentNews);	
		timeOutNews = setTimeout("News.slideShow()", this.timeout);
	}
};



/*
--------------------------------------------------------------------
FUNCTION EQUALIZE COLUMNS

	USAGE:
	$().ready(function() {
		$("#col1, #col2, #col3").equalizeCols();
	});
--------------------------------------------------------------------
*/
jQuery.fn.equalizeCols = function(){
	var height = 0;
	return this.css("height","auto").each(function(){
		height = Math.max( height, jQuery(this).outerHeight() );
	}).css("height", height);
}; 



/*
--------------------------------------------------------------------
STARTS JQUERY
--------------------------------------------------------------------
*/
$(document).ready(function(){
	Services.init();
	News.init();
	
	//Equalize Columns
	$("#aboutUs, #services").equalizeCols();
});