// JavaScript Document
//Use this to set the date to which the timer counts down to
//Edit line 23. Input your desired date using the format below:
//
// 		newYear = new Date(yyyy, 00 - 1, dd, hh, mm, ss);
//
// where yyyy = year, oo = month (e.g. Sep = 09), dd = day, hh = hour (e.g. 5pm = 17), mm = min and ss = seconds
//
// for example, July 12th, 2012, at 18:43pm would be written as below:
//
// 		newYear = new Date(2012, 07 - 1, 12, 18, 43, 00);
	//modify line 23 below to use your own launch date, following the instructions above:
(function($){
//parse url &cookies
var cookie_aff_anchor = 'CS'; 
var cookie_aff_name = 'CS_aff'; // nom du cookie a placer
var cookie_expire = 35; //expiration en jours
var cookie_defaut_value = 'Alexaloola'; //cookie par defaut : pseudo ou id sql ( admin par exemple )
var url = $.url(); // parse the current page URL
var anchor = url.attr('fragment'); // returns '#...'
//console.log($.cookie(cookie_aff_name));
if ($.cookie(cookie_aff_name) === null){ //pas de cookie aff, on continue
    if (anchor.search(cookie_aff_anchor + "_") == -1){  //anchor non valide
            $('#hidden_parrain').val(cookie_defaut_value);
    				$.cookie(
                        cookie_aff_name, 
                        cookie_defaut_value, 
                        { 
                            expires: cookie_expire, 
                            domain: 'code-seo.com',
                            path : '/' 
                        }
                    ); 
    }else{
    				var aff = anchor.split("_");
                    aff = (aff[1]);
                    $('#hidden_parrain').val(aff);
                    //ajax
                    $.ajax({
                      url: 'js/aff.php?aff='+escape(aff),
                      success: function(data) {
                        //console.log(data);
                        $.cookie(
                            cookie_aff_name, 
                            aff, 
                            { 
                                expires: parseInt (data), 
                                domain: 'code-seo.com',
                                path: '/' 
                            }
                        ); 
                      },
                      error: function(){
                           $.cookie(
                                cookie_aff_name, 
                                cookie_defaut_value, 
                                { 
                                    expires: cookie_expire, 
                                    domain: 'code-seo.com',
                                    path: '/' 
                                }
                            ); 
                      },
                      statusCode: {
                            404: function() {
                              alert('cookie page not found');
                            }
                      }
                    });
    }
}

/*if ($.cookie(cookie_aff_name) != null){*/
    

/*} */
// create $.cookie('the_cookie', 'the_value', { expires: 7, path: '/' });    
// $.cookie('the_cookie'); // => 'the_value'
// $.cookie('not_existing'); // => null   
	$('#months p').countdown({
		until: newYear, 
		format: 'yODHMS',
		layout: '{on}'
	});
	$('#days p').countdown({
		until: newYear, 
		format: 'ODHMS',
		layout: '{dn}'
	});
	$('#hours p').countdown({
		until: newYear, 
		format: 'ODHMS',
		layout: '{hn}'
	});
	$('#minutes p').countdown({
		until: newYear, 
		format: 'ODHMS',
		layout: '{mn}'
	});
	$('#seconds p').countdown({
		until: newYear, 
		format: 'ODHMS',
		layout: '{sn}'
	});
//email mailing-list submit 
$('#submitform').submit(function(){
		var action = $(this).attr('action');
		$("#message").slideUp(750,function() {
		$('#message').hide();
 		$('#submit')
			.after('<img src="images/ajax-loader.gif" class="loader" />')
			.attr('disabled','disabled');
		$.post(action, { 
			email: $('#email').val()
		},
			function(data){
				document.getElementById('message').innerHTML = data;
				$('#message').slideDown('slow');
				$('#submitform img.loader').fadeOut('slow',function(){$(this).remove()});
				$('#submitform #submit').attr('disabled',''); 
				if(data.match('success') != null) $('#submitform').slideUp('slow');
			}
		);
		});
		return false; 
	});
//image hover
$('img.img_hover').hover(
    function(){
        var src = $(this).attr('src');
        src = src.replace('.png','_hover.png');
        $(this)            
            .attr('src', src);
    },
    function(){
        var src = $(this).attr('src');
        src = src.replace('_hover.png','.png');
        $(this)
            .attr('src', src);
    }
    );
//deroulement panneau description
$('.description_content').hide();
$('.deploy').hover(function(){
    $(this).css({'cursor':'pointer'});
    });
$(".deploy").toggle(function() { 
                      $(".description_content").fadeIn("slow");
                      $('#main-bg').css({'overflow':'visible'});
                      },
                       function() { 
                     $(".description_content").fadeOut("slow"); 
                    });



//animation texte





$('.anim > up').hide();    
$('.anim').hover(
    function(){
        $('.anim > up').fadeIn(200);
    },
    function(){
        $('.anim > up').fadeOut(200);
    }
    );
    
//popup cgv et mentions légales
$('.popup').popupWindow({
    height:500, 
    width:800, 
    centerBrowser:1 
});
})(jQuery);
