function bookmark(title,url) {
	if (window.sidebar) {
		window.sidebar.addPanel(title, url,""); 
	} else if(document.all) {
		window.external.AddFavorite(url, title);
	} else if(window.opera && window.print) {
		return true;
	}
}

function PopCommentaire(id) {
	winwidth = 600;
	winheight = 300;
	window.open('/commentaire-'+id+'.html', '_blank', 'scrollbars=yes, width=' + winwidth + ', height=' + winheight + ', top='+ (screen.availHeight - winheight) / 3 +', left='+ (screen.availWidth - winwidth) / 2 +', resizable');
}

function global_resize() {
	var minwidth, totalwidth;
	minwidth = document.getElementById("divglobal").offsetWidth + document.getElementById("divvban").offsetWidth + 10;
	totalwidth = document.getElementById("divglobal").offsetWidth + (document.getElementById("divvban").offsetWidth + 10) * 2;
	if (screen.width <= minwidth) document.getElementById("divglobal").style.margin='0px';
	else if (screen.width <= totalwidth) document.getElementById("divglobal").style.margin='0px auto 0px '+ Math.round((screen.width - minwidth ) * 0.5) +'px';
}

function slideSwitch() {
    var $active = $('.slideshow DIV.active');

    if ( $active.length == 0 ) $active = $('.slideshow DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('.slideshow DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

//
function slideSwitch2() {
    var $active = $('.slideshow2 DIV.active');

    if ( $active.length == 0 ) $active = $('.slideshow2 DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('.slideshow2 DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function popUnder() {
	TheNewWin = window.open("http://www.espace-plus.net/redir/rotation_redir.php?id_rotation=42&id=16204&tracker=TEST_cdTplP",'TheNewpop','toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1');
	TheNewWin.blur();
	window.focus();
}

$(function() {
	setInterval( "slideSwitch()", 3000 );
	setInterval( "slideSwitch2()", 5000 );
	$('.mcv_close_pop').click(function() {
		$('.mcv_pop').animate({top: "-400px"}, 600);
		//$('html').animate({scrollTop:0}, 'fast'); 
		email_focus('mail1');
		$('.dim').hide();
		return false;
	});

	$('#divglobal a.showForm').click(function() {
		$('.mcv_pop').animate({ top: "100px"}, 600);
		$('#mcv_popPic').attr('src', $(this).attr('label'));
		//$('html').animate({scrollTop:0}, 'fast'); 
		email_blur('mail1');
		//popUnder();
		$(".dim").show();
		return false;
	});
	
	$('.dim').css('height', $(document).height());
});

var REG_MAIL = /^[\w-\.]{2,}@[\w-]{1,}\./;

//BLINK - IE does not understand the blink css
var timers = new Object();
var visible = new Object();
visible['mail1'] = 1;
visible['mail2'] = 1;
var texts = new Object();

function blink(id){
	if (visible[id]==1){
		texts[id] = document.getElementById(id).value;
		document.getElementById(id).value = '';
		visible[id] = 0;
	} else {
		document.getElementById(id).value = texts[id];
		visible[id] = 1;
	}
}

function start_blink(id){
	if (document.getElementById(id).value=='@'){
		if (id=='mail1') {
			timers[id] = setInterval('sb1()', 500);
		} else if (id=='mail2') {
			timers[id] = setInterval('sb2()', 500);
		}
	}
}

function sb1() {
	blink('mail1');
}

function sb2() {
	blink('mail2');
}

function stop_blink(id) {
	if (timers[id]){
		clearInterval(timers[id]);
	}
}

function email_focus(id){
	stop_blink(id);
	if (document.getElementById(id).value == '@') document.getElementById(id).value = '';
}

function email_blur(id){
	if (document.getElementById(id).value == '@' || document.getElementById(id).value == ''){
		document.getElementById(id).value = '@';
		start_blink(id);
	}
}

function check(email){
	if(!REG_MAIL.test(document.getElementById(email).value)){
		alert("Votre email doit "+String.fromCharCode(234)+"tre valable pour recevoir votre acc"+String.fromCharCode(232)+"s gratuit !!!");				
		document.getElementById(email).focus();
	}
	else{
		winwidth = screen.availWidth; winheight = screen.availHeight;
		cbpop = window.open("http://www.unewebcam.com/email.php?s="+winwidth+"&t="+document.getElementById('t').value+"&email="+document.getElementById(email).value, '_blank', 'scrollbars=1, width='+winwidth+', height='+winheight+', left='+(screen.availWidth-winwidth)/2+', top='+(screen.availHeight-winheight)/2);
	}
}
