jQuery(function() {

	initCalls();


	//
        /*
	jQuery("#tree").treeview({
		collapsed: true,
		persist: "location"
	});
*/

	sidebarHeight();


	// Set jQuery popup
	jQuery('.overlay').overlay({
		expose: {
			color: '#000000',
			loadSpeed: 200,
			opacity: 0.6
		},
		top: 'center'
	});


	// Set jQuery tabs
	jQuery('.tabs-bar-nav').tabs('div.tabs-bar-content > div');


	// Set sifr replace for popup headlines - "display: none" bug
	jQuery('.overlay').click(function() {
		sifrReplace();
	});
	
	// Affiche le formulaire de l'abonnement à la newsletter
	$('#newsletter').load('/subscription/index',{'new':true},subscription);
	
})





/////
function initCalls()
{
	// Shadow for popup window - these are NOT valid properties W3C
	jQuery('.overlay-all').css({
		'-moz-box-shadow' : '0px 5px 10px #000000',
		'-webkit-box-shadow' : '0px 5px 10px #000000'
	});


	// Rounded corner for inputs
	jQuery('.input-type-text, .fixed-header input').css({
		'-moz-border-radius' : '2px',
		'-webkit-border-radius' : '2px'
	});


	// Safari product popup border fix
	if (jQuery.browser.safari) {
		jQuery('.overlay-content').css('width', '745px');
	}

	
	// Firefox sIFR bug - sIFR titles have 2px left padding
	if (jQuery.browser.mozilla) {
		jQuery('.sIFR-replaced').css({
			'position' : 'relative',
			'left' : '-2px'
		});

		jQuery('.search-title-box h2').css('padding-left', '10px');
	}
}

// Set sidebar height
function sidebarHeight()
{
	var sidebarH = jQuery('.section').height();
	jQuery(".sidebar").css({
		'height' : sidebarH - 30
	});
}

// sIFR replacement
function sifrReplace()
{
	sIFR.replace(barmenoMed, {
		selector: '.overlay-all h1',
		css: '.sIFR-root { color: #005138; font-size: 23px }',
		tuneHeight: '-5px',
		wmode: 'transparent'
	});
}

function subscription(responseText, textStatus, XMLHttpRequest){
	$('#subscriberPopin').overlay(
		{
			fixed: true,
			mask: {color: '#000',loadSpeed: 200,opacity: 0.7},
			closeOnClick: true,
			load: true
		}
	);
	$('#subscriberSubmit').click(function() {
		date = new Date();
		$('#newsletter').load($("#subscriberForm").attr('action')+'?uid='+date.getTime(),$("#subscriberForm").serialize(),subscription);		
	});
}
