jQuery(document).ready(function() {
	var zoomheight = jQuery('#single-detail').height();
/*	jQuery('.zoomify').jqzoom({
	    zoomWidth: 400,
	    zoomHeight: zoomheight + 30,
		showEffect : 'fadein',
		hideEffect : 'fadeout',
		xOffset : '10',
		title: false
		});*/
		
	rollMenu( jQuery('#navbar > li') );
	selectMag();
	
	jQuery('.more-detail').hide();
	jQuery('div.produit').mouseenter(function(){
		jQuery(this).addClass('borderred').find('.more-detail').fadeIn('fast');
		jQuery(this).find('.info-produit').addClass('bggrey');
		}).mouseleave(function(){
		jQuery(this).removeClass('borderred').find('.more-detail').fadeOut('fast');
		jQuery(this).find('.info-produit').removeClass('bggrey'); 
	});
	
	jQuery('#slideshow').cycle({
        fx:     'fade',
        timeout: 7000,
        pager:  '#nav',
		slideExpr: 'img'
    });
	
	jQuery('#collection').hover(
        function() { jQuery('#controls').fadeIn(); },
        function() { jQuery('#controls').fadeOut(); }
    );
	
	jQuery('#collection').cycle({
		fx:     'fade',
        speed:   400,
        timeout: 7000,
        next:   '#next',
        prev:   '#prev'
	});
	
	jQuery('#traplink li a img').hover(function(){
		jQuery(this).fadeTo("fast", 0.7); }, function(){
		jQuery(this).fadeTo("fast", 1);	
	});	
	
	$("a#size-guide").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	100, 
		'speedOut'		:	100
	});	
	
	$("a.bookbox").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	100, 
		'speedOut'		:	100
	});					
});

function rollMenu( el ){
	el.mouseenter( function(event){
		jQuery(this).addClass('current-nav').find('.sub-menu').fadeIn('fast')
	}).mouseleave( function(event) {
		jQuery(this).removeClass('current-nav').find('.sub-menu').fadeOut('fast');
	});
};

/*--MAGASINS--*/
var dropMenus;
var initor;

function selectMag() {
	dropMenus = jQuery('#select-pdv .menudrop');
	
	dropMenus.find('a').click( function(event) { event.preventDefault(); } );
	initor = dropMenus.find('a.initor');
	dropMenus.find('a.initor').mouseenter( function() {
		jQuery(this).next('ul').css({ 'z-index' : 200 }).slideDown( 200 );
		dropMenus.mouseleave( function() {
			jQuery(this).find('ul').css({ 'z-index' : 5 }).slideUp( 100 );
		});
	});
	
	if ( initor.next('ul').find('a').length > 0 ) {
		initor.next('ul').find('a').click( function(e) {
			findMag( jQuery(this).attr('rel'), jQuery(this).text() );
		});
	}
};

function findMag( where, value ) {
	jQuery.ajax({
		type: 'POST',
		url: tPath + '/ajax_mag.php',
		data: 'where=' + where + '&value=' + value,
		success: function( result ) {
			if ( where == 'shop_country' ) {
				jQuery('#select-pdv').empty();
				jQuery('#select-pdv').append(result);
			} else if ( where == 'shop_town' ) {
				getPost( where, value );
				jQuery('#select-pdv').find('.menudrop:last').remove();
				jQuery('#select-pdv').append(result);
			}
		},
		complete: function() {
			dropMenus.find('a').unbind();
			Cufon.replace( '#select-pdv .avenir-roman' , { fontFamily: 'avenirroman' });
			Cufon.replace( '#select-pdv .rockwell' , { fontFamily: 'rockwell' });
			selectMag();
		}
	});
};

function getPost( where, value ) {
	jQuery.ajax({
		type: 'POST',
		url: tPath + '/ajax_mag.php',
		data: 'sort=true&where=' + where + '&value=' + value,
		success: function( result ) {
			jQuery('#show-pdv').empty().append(result);
		},
		complete: function() {
			Cufon.replace( '#show-pdv .avenir-roman' , { fontFamily: 'avenirroman' });
			Cufon.replace( '#show-pdv .rockwell' , { fontFamily: 'rockwell' });
		}
	});
};

function twitterShare() {
    window.open('http://twitter.com?status=' + encodeURIComponent(document.title + ' - ' + document.location));
}
function facebookShare() {
    var d = document,
        f = 'http://www.facebook.com/share',
        p = '.php?src=bm&v=4&i=1259575049&u=' +
            encodeURIComponent(document.location.href) +
            '&t=' + encodeURIComponent(d.title);
    function a() {
        if (!window.open(f + 'r' + p, 'sharer', 'toolbar=0,status=0,resizable=1,width=626,height=436')) {
            document.location.href = f + p;
        }
    }
    if (/Firefox/.test(navigator.userAgent)) {
        setTimeout(a, 0);
    } else {
        a();
    }
}


