;

function getFlashObj(movie){
	if (window.document[movie]) {
		return window.document[movie];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1) {
		if (document.embeds && document.embeds[movie]) {
			return document.embeds[movie]; 
		}
	} else {
		return document.getElementById(movie);
	}
}

function _exemple_swf_show(movie, ref) {
	var width;
	var height;

	var movieObj = getFlashObj(movie);
	//width = movieObj.TGetPropertyAsNumber("/", 8);
	//height = movieObj.TGetPropertyAsNumber("/", 9);
	width = movieObj.TGetProperty("/", 8);
	height = movieObj.TGetProperty("/", 9);
	if(typeof width == 'undefined') {
		window.setTimeout(_exemple_swf_show, 1000, movie, ref);
		return false;
	}
	//showDim(movie,width,height);
	$('#flash-exemple-div').remove();
	var msg = '<div style="width:'+width+'px; height:'+height+'px;"><!--[if !IE]> --><object type="application/x-shockwave-flash" data="'+ref+'" width="'+width+'" height="'+height+'"> <!-- <![endif]--><!--[if IE]><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+width+'" height="'+height+'"><param name="movie" value="'+ref+'" /><!--><!--dgx--><param name="loop" value="true" /><param name="menu" value="false" /><param name="wmode" value="opaque" /></object><!-- <![endif]--></div>';

	var top = ($(window).height() - height) /2;
	if(top < 0) {
		top = 0 - $('body').height();
	}
	var left = ($(window).width() - width) /2;
	if(left < 0) {
		left = 0;
	}
       	$.blockUI({ 
		message: $(msg),
		css: {
			position: 'relative',
			top:  top + 'px', 
			left: left + 'px', 
				width: width + 'px',
				height: height + 'px'
			},
		/*fadeIn: 500,*/
		fadeOut: 500
        });
	window.scrollTo(0,0); 
	$('.blockOverlay').attr('title','Retour').click($.unblockUI);
   	return false;
}

function showDim(movie,width,height) {  
 alert("The current dimensions for the Flash Object ("+movie+") are "+width+" in width and "+height+" in height.");
}

function sorman_exemple_swf_show(item) {
		$.blockUI.defaults.overlayCSS.cursor = 'default';
		$.blockUI.defaults.css.cursor = 'default';
		$.blockUI({ message: 'Chargement en cours ...' });
		var ref = item.attr('href');
		//var ref = 'test.swf';
		var msg = '<div id="flash-exemple-div" style="width:0px; height:0px; overflow:hidden;">\
<object id="flash-exemple" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0">\
<param name="movie" value="'+ref+'" />\
<param name="loop" value="true" />\
<param name="menu" value="false" />\
<param name="wmode" value="opaque" />\
<param name="swliveconnect" value="true" />\
<param name="allowscriptaccess" value="samedomain" />\
<embed src="'+ref+'" id="flash-exemple" name="flash-exemple" allowscriptaccess="samedomain" swliveconnect="true" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash">\
</embed>\
</object>\
</div>';

		$('body').append(msg);
		_exemple_swf_show('flash-exemple', ref);
		return false;
}


function sorman_logout(item) {
	window.location.href = item.attr('href')+"?logout=1";
	return false;
}

function sorman_login(item, idArticle) {
	window.location.href = item.attr('href');
	return;
}

function sorman_login_article(item, idArticle) {
	$.ajax({
		url: '/checkLogin.html',
		cache: false,
		type: 'get',
		dataType: 'text',
		success: function(text) {
			if(text == 'OK') {
				window.location.href = item.attr('href');
			} else {
				$.blockUI({ message: $('#login-box'), css: { cursor: 'default' },overlayCSS: { backgroundColor: 'black'} });
				$('.blockOverlay').attr('title','Retour').click($.unblockUI);
				$('#login-submit').unbind('click').click(function() {
					$.blockUI({ message: "<h4>V&eacute;rification ...</h4>" });
					$.ajax({
						url: '/doLogin.html',
						data: { 'username':$('#login-user').val(),'password':$('#login-pass').val()},
						cache: false,
						type: 'post',
						dataType: 'text',
						success: function(text) {
							if(text == 'OK') {
								window.location.href = item.attr('href');
								return true;
							}
							$.blockUI({ message: "<h4>Nom d'utilisateur ou mot de passe incorrect</h4>" });
							//$.blockUI({ message: "<h4>"+text+"</h4>" });
							$('.blockOverlay').attr('title','Retour').click($.unblockUI);
						},
						error: function(text) {
							$.blockUI({ message: "<h4>Erreur lors de la v&eacute;rification !</h4>" });
							$('.blockOverlay').attr('title','Retour').click($.unblockUI);
						}
					});
					$('.blockOverlay').attr('title','Retour').click($.unblockUI);
				});
			}
		},
		error: function() {
			alert('Not found');
		}	
	});
	return false;		
}

function sorman_get_password() {
				$.blockUI({ message: $('#login-lost-box'), css: { cursor: 'default' },overlayCSS: { backgroundColor: 'black'} });
				$('.blockOverlay').attr('title','Retour').click($.unblockUI);
				$('#login-lost-submit').unbind('click').click(function() {
					$.blockUI({ message: "<h4>Traitement en cours ...</h4>" });
					$.ajax({
						url: '/doGetLostPassword.html',
						data: { 'email':$('#login-lost-email').val()},
						cache: false,
						type: 'post',
						dataType: 'text',
						success: function(text) {
							if(text == 'OK') {
								$.blockUI({ message: "<h4>Votre mot de passe a été renvoyé par courrier électronique.</h4>" });
							} else {
								$.blockUI({ message: "<h4>Adresse email incorrecte.</h4>" });
							}
							$('.blockOverlay').attr('title','Retour').click($.unblockUI);
						},
						error: function(text) {
							$.blockUI({ message: "<h4>Erreur de traitement !</h4>" });
							$('.blockOverlay').attr('title','Retour').click($.unblockUI);
						}
					});
					$('.blockOverlay').attr('title','Retour').click($.unblockUI);
				});
	return false;		
}


function sorman_portail_startup() {
		$('#decouverte-menu-zone').hover(function() {
			$('#decouverte-menu').stop(true,true);
			$('#decouverte-menu').delay(200).slideDown(500);
		}, function() {
			$('#decouverte-menu').stop(true,true);
			$('#decouverte-menu').slideUp(500);
		});

		
		$('#offre-decouverte-zone').hover(function() {
			$('#offre-decouverte-lien').stop(true,true);
			$('#offre-decouverte-lien').delay(200).slideDown(500);
		}, function() {
			$('#offre-decouverte-lien').stop(true,true);
			$('#offre-decouverte-lien').slideUp(500);
		});

		$('.mv-block').hover(function(){
			$(this).find('.mv-sous-rubrique').stop(true,true);
			$(this).find('.mv-sous-rubrique').delay(200).addClass('mv-opened').slideDown(500);
		}, function() {
			$(this).find('.mv-sous-rubrique').stop(true,true);
			$(this).find('.mv-sous-rubrique').slideUp(500).removeClass('mv-opened');
		});

		$('#abonne-menu-zone').hover(function(){
			$('#abonne-menu').stop(true,true);
			$('#abonne-menu').delay(200).slideDown(500);
		}, function() {
			$('#abonne-menu').stop(true,true);
			$('#abonne-menu').slideUp(500);
		});

		/*$('#abonne').hover(function(){
			$('#abonne-menu').stop(true,true);
			$('#abonne-menu').delay(200).slideDown(500);
		}, function() {
			$('#abonne-menu').stop(true,true);
			$('#abonne-menu').slideUp(500);
		});*/

		$('#agenda-menu-zone').hover(function(){
			$('#agenda-menu').stop(true,true);
			$('#agenda-menu').delay(200).slideDown(500);
		}, function() {
			$('#agenda-menu').stop(true,true);
			$('#agenda-menu').slideUp(500);
		});

		$('#offre-decouverte-lien').hide();
		$('#decouverte-menu').hide();
		$('.mv-sous-rubrique').hide();
		$('#abonne-menu').hide();
		$('#agenda-menu').hide();
}
;

