$(document).ready(function(){
	$("#mainmenu ul li").hoverIntent(
		function(){ 			
			$("ul", this).slideDown("fast");
			if( $(this).find('.tell').length ) {
				$(this).addClass( 'tellme' );
			} else {
				$(this).addClass( 'over' );
			}
		}, 
		function() { 
			$("ul", this).slideUp("fast"); 
			if( $(this).find('.tell').length ) {
				$(this).removeClass( 'tellme' );
			} else {
				$(this).removeClass( 'over' );
			}
		} 
	);
	$(".button").click( function() {
		$(this).blur();
	});
	
	
	if( $('#actnum').length ) {
		$('#actnum').val('');
		//$('#actnum').focus();
	}
	
});





var interval = 5000;
var ad_count;
var ad_interval;
var old_ad = 0;
var current_ad = 0;

$(document).ready(function() {
	$( "#ads-shell" ).append( '<span class="prev btn"></span><span class="next btn"></span>' );
	$( ".prev, .next" ).fadeTo( 0, 0.5 );
	$( ".prev" ).click( function(i) {
		i.preventDefault();
		rotate_ad( 'prev' );
	});
	$( ".next" ).click( function(i) {
		i.preventDefault();
		rotate_ad( );
	});
	$( ".next, .prev" ).hover( 
		function() { $( this ).fadeTo( 'fast', 1 ); },
		function() { $( this ).fadeTo( 'fast', 0.5 ); 
	});
	ad_count = $("#ads li").length;
	$("#ads li").each( function(i) { $(this).hide(); });
	$( "#ads li:eq(" + current_ad + ")" ).fadeIn("slow");
	ad_interval = setInterval( rotate_ad, interval );
	$('#ads-shell').hover(
		function() { clearInterval( ad_interval ); },
		function() { ad_interval = setInterval( rotate_ad, interval );
		//rotate_ad();
	});
});

function rotate_ad( direction ) {
	if( direction == 'prev' ) {
		current_ad = (old_ad - 1);
		if( current_ad == -1)
			current_ad = ad_count-1;
	} else {
		current_ad = (old_ad + 1) % ad_count;
	}
	$("#ads li:eq(" + old_ad + ")").fadeOut("slow", function() {
		$("#ads li:eq(" + current_ad + ")").fadeIn("slow");
	});
	old_ad = current_ad;
}



$(document).ready(function() {
	var images = new Array(
		"/images/main/main_image1.jpg",
		"/images/main/main_image2.jpg",
		"/images/main/main_image3.jpg"
	);
	var index = Math.floor( Math.random()*images.length );
	//alert( images[index] );
	$("body.home #headcontainer").css( 'background','url('+images[index]+')' );
});








