// JavaScript Document

function fadein() {
	$(this).children('div.carousel_info').fadeTo("slow", 1.0);
	}
	
function fadeout() {
	$(this).children('div.carousel_info').fadeTo("fast", 0);
	}

//Image carousels on front and subpages
function carousels() {
    //Carousel on front page
    $("#frontpage_carousel").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		scroll:1,
		visible:1,
		speed:500
    });

	//Mediabox on sub pages
	$("#mediabox_carousel").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		scroll:1,
		visible:1,
		speed:500
	});
	

	
	
	var config = {    
	 sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
	 interval: 200, // number = milliseconds for onMouseOver polling interval    
	 over: fadein, // function = onMouseOver callback (REQUIRED)    
	 timeout: 500, // number = milliseconds delay before onMouseOut  
	 out:fadeout
	};

	$("#mediabox_carousel li").hoverIntent(config);
	
}




function provider_navi_over() {
	$(this).animate({backgroundPosition: '(0 0)'},
				    {duration:500}
	);
}

function provider_navi_out() {
	$(this).animate({backgroundPosition: '(0 -159px)'},
				    {duration:500}
	);
}


function provider_menu(){
	//providermenu mouseover on frontpage

	var config = {    
	 sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
	 interval: 70, // number = milliseconds for onMouseOver polling interval    
	 over: provider_navi_over, // function = onMouseOver callback (REQUIRED)    
	 timeout: 10, // number = milliseconds delay before onMouseOut  
	 out:provider_navi_out
	};

	$("#frontpage_provider_navi a").hoverIntent(config);
	

}


// Stylize content area corners with jQuery plugin
function stylize_corners() {
	//stylized corners
	$(".corner").corner("bevel, tr");

	}
	
function main_navi_slides() {
	//slide content in main navigation
	$("#providers_slide").hide();
	$("#about_helsinkiart_slide").hide();
	
	$("#about_helsinkiart_slide_toggle").click(function(){
		$("#providers_slide").hide();
		$("#about_helsinkiart_slide").slideToggle();
		return false; 
	});
	
	$("#about_close").click(function(){
		$("#about_helsinkiart_slide").slideToggle();
		return false; 
	});
	
	$("#providers_slide_toggle").click(function(){
		$("#about_helsinkiart_slide").hide();
		$("#providers_slide").slideToggle();
		return false; 
	});
}

function calendar_option_slide() {
	$("#calendar_options_container").hide();
	$('#calendar_options_slide_toggle').click(function(){
		$("#calendar_options_container").slideToggle();
		return false;
	});
}




// create and show on mouseclick help dialogs
function help_popups() {
	// First we create dialogs on document load
	// hide all help dialogs
	$('.help').each(function() {
		var $iid = $(this).attr("id");
		// create id of help dialog
		var id_stringi = '#' + $iid;
		// show dialog 
			$(id_stringi)
			.dialog({
				resizable:false,
				modal:true,
				autoOpen:false
			});
	});
	
	
	//show individual dialogs on mousedown
	$('.help_btn').click(function() {
		var $iid = $(this).attr("id");
		// create id of help dialog
		var id_string = '#' + $iid + '_dialog';
		$(id_string).show();
		// get id of clicked element 
		$(id_string).dialog('open');
		return false; 
	});
}
	

// Sort tables in admin-mode
function sort_tables() {
	$(".sort")
	.tablesorter({
		widgets: ['zebra'],
		widthFixed: true
	})
	.tablesorterPager({
		container: $("#pager")});							
}

function admin_tabs() {
	$("#admin_tabs").tabs();
	}
	
function add_bookmarks(){
	$('.share').bookmark({sites: 
    ['delicious', 'digg', 'facebook', 'google', 'myspace'],
	icons: '/images/bookmarks.png',
	addEmail: true,
	popup:true,
	popupText:'Bookmark'
	});
}
	
function datepicker() {
		$(".datepicker").datepicker(
		{ dateFormat: 'd-m-yy' }							
									);
}





$(document).ready(function () {
	$("#mediabox_carousel .carousel_info").fadeTo(0,0); // This sets the opacity of the info-boxes to zero at page load
	$('html').addClass('js');  

	provider_menu();
	datepicker();
	main_navi_slides();
	calendar_option_slide();
	help_popups();
	add_bookmarks();
	
	
  });


var browserName=navigator.appVersion;

if(browserName.indexOf('Safari') != -1) {
  $(window).load(function () {
  	carousels();
  });
} else {
  $(document).ready(function () {
  	carousels();
  });
}	
