$(document).ready(function() {
	
	$("#tabs").tabs(".pane");
	$(".tick_content").scrollable({circular: true, mousewheel: true});
	$(".scroller").scrollable({circular: true, mousewheel: true});
	$(".promo-slider").scrollable({circular: true, mousewheel: true}).navigator().autoscroll({ autoplay: true, interval: 6000 });
	
	$("a[rel^='prettyPhoto']").prettyPhoto();
	
	//login box	
	if ($('#login_box').length > 0) {
		clear_input('username','Username');
		clear_input('password','Password');
		//$("#login_box").css("display", "none");
		
		$("#client_link").click(function(event){
			event.preventDefault();
			$("#login_box").addClass("show");
			$("#login_box").slideToggle('fast');
		});
	
	}
	
	function clear_input(field,message){	
		if($("#"+field).attr("value") != ""){
			message = $("#"+field).attr("value");
		}//end if
		$("#"+field).val(message);
		$("#"+field).focus(function(){
			myValue = $("#"+field).val();
			if (myValue == message) { $(this).val(""); }
		});
		$("#"+field).blur(function(){
			myValue = $("#"+field).val();
			if (myValue == "") { $(this).val(message); }
		});
	}
	
	var max_height = 0;
    function widgetsSameHeight( elements ) {
        elements.each(function(){
             if($(this).height() > max_height){
                max_height = $(this).height();   
            }
        });

        elements.height(max_height);
    }

	//set heights for Mega Menu elements
	widgetsSameHeight( $('.master') );
	
	
	//make divs clickable
	$(".box").click(function(){
     window.location=$(this).find("a").attr("href");
     return false;
});
	
	
	//mega menu
	
	function addMega(){
    	$(".mega").addClass("megavis");
		$(".mega").slideToggle('fast');
		$(this).find("a.top").addClass("sel");
		
    }

    function removeMega(){
		$(".mega").slideToggle('fast');
		$(this).find("a.top").removeClass("sel");
    }
		
		
	if ($('#nav_ict a').length) {
		$(".mega").css("display", "none");
		
		var megaConfig = {
			interval: 0,
			sensitivity: 5,
			over: addMega,
			timeout: 200,
			out: removeMega
		};
	
		$("#nav_ict").hoverIntent(megaConfig);
	
	}

});
