$(function()
{
	$('.scroll-pane_home').jScrollPane({showArrows: true});
	$('.scroll-pane').jScrollPane({showArrows: true});
	$('.scroll-pane_quoi').jScrollPane({showArrows: true});
	$('.scroll-pane_white').jScrollPane({showArrows: true});
	$('.scroll-pane_application').jScrollPane({showArrows: true});
	$('.scroll-pane_teaser').jScrollPane({showArrows: true});

	try{
		at_attach("btnAddThis", "menu_child", "hover", "y", "pointer");
	} catch(err){}

	$("#btn_newsletter").click(function () {
		var email = $("#txt_email").val();
		$.post("/ajax/addnewsletter", 
				{email:email},
				function(data){
					$.fancybox(
						'<p>'+data+'</p>',
						{'autoDimensions'	: false,
						 'width'			: 300,
						 'height'			: 30}
						
					);

				}, 
				"html"
		);
	});


	$("#lavaLampBasicImage li").each(
		function(){
			if($(this).attr('class') == 'selectedLava'){
				try{
					show_menu($(this));
				} catch(err) {}
			}
		}
	);
	
	$("#lavaLampBasicImage li").hover(
		function(){
			if($(this).attr('class') != 'selectedLava'){
				try{
					show_menu($(this));
				} catch(err) {}
			}
		}, 
		function(){
			if($(this).attr('class') != 'selectedLava'){
				try{
					hide_menu($(this));
				} catch(err) {}
			}
		}
	);
	
	$("#lavaLampMulti li").each(
		function(){
			if($(this).attr('class') == 'selectedLava'){
				try{
					show_menu($(this));
				} catch(err) {}
			}
		}
	);
	
	$("#lavaLampMulti .submenu li").hover(
		function(){
			if($(this).attr('class') != 'selectedLava'){
				try{
					show_menu($(this));
				} catch(err) {}
			}
		}, 
		function(){
			if($(this).attr('class') != 'selectedLava'){
				try{
					hide_menu_png($(this));
				} catch(err) {}
			}
		}
	);
	
	$(document).pngFix(); 
	jQuery('#lavaLampMulti').accordion({
			active: false,
			header: '.expandable',
			navigation: true,
			event: 'click',
			animated: 'easeslide',
			collapsible: true,
			autoHeight: false,
			active: false, 
			alwaysOpen: false
		});
	
	//for quand, vision and method
	$("a#single_image").fancybox();		

});
	
function show_menu(obj){
	var iconName = obj.find("img").attr("src");
	var origen = iconName.split("_ori.")[0];
	obj.find("img").attr({src: "" + origen + "_selected.gif"});

	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
	if(ie6){
		var newstyle = obj.find("span").attr('style');
		newstyle = newstyle.replace(iconName, origen + "_selected.gif");
		newstyle = newstyle.replace(/width:\s+\d+/i, 'width:188');
		obj.find("span").attr('style', newstyle);
	}

}

function hide_menu(obj){
	var iconName = obj.find("img").attr("src");
	var origen = iconName.split("_selected.")[0];
	obj.find("img").attr({src: "" + origen + "_ori.gif"});

	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
	if(ie6){
		var newstyle = obj.find("span").attr('style');
		newstyle = newstyle.replace(iconName, origen + "_ori.gif");
		obj.find("span").attr('style', newstyle);
	}

}

function hide_menu_png(obj){
	var iconName = obj.find("img").attr("src");
	var origen = iconName.split("_selected.")[0];
	obj.find("img").attr({src: "" + origen + "_ori.png"});

	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
	if(ie6){
		var newstyle = obj.find("span").attr('style');
		newstyle = newstyle.replace(iconName, origen + "_ori.png");
		newstyle = newstyle.replace(/width:\s+\d+/i, 'width:77');
		obj.find("span").attr('style', newstyle);
	}

}

function toggleValue(input, defaulttext) {
	if($('#'+input).val() == defaulttext) {
		$('#'+input).val('');
	} else { 
		if($('#'+input).val() == '') {
			$('#'+input).val(defaulttext);
		}
	}
}

