this.debug = function(e, al){
	if( al ){
		alert( e )
		return;
	}
	
	if( typeof(console) != 'undefined' ){
		console.log( e )
	} else {
		$('<div style="position: fixed; top: 10px; left: 10px; background: pink; color: black; padding: 10px; border: 2px solid red;"><span style="display: block; font-size: 10px;">opus2 JS Debugger:</span>' + e + '</div>').appendTo('body')
	}
} 

this.mainnav = function(e) {
	if ( $(e).length ) {
		$(e + ' > dl').hover(
			function(){
				$(this).addClass('active').parent().find('dl').not('.active').stop().fadeTo(300, 0.3)
			},
			function(){
				$(this).removeClass('active').parent().find('dl').stop().fadeTo(100, 1)
			}
		)
	}else{
		return false
	}
}

this.catshorts = function (e, t){
	if ( $(e).length ) {
		if( $(e).height()-5 > t) {
			
			var h = $(e).height()
			
			$(e).height(t).css('overflow', 'hidden').append('<li id="ctrlMore">voir plus...</li>').hover(
				function(){ $(this).stop().animate({height: h + 'px'}, 300).find('li#ctrlMore').fadeOut(200) },
				function(){ $(this).stop().animate({height: t + 'px'}, 300).find('li#ctrlMore').fadeIn(200) }
			)
			
			
		}else{
			return
		}
	}else{
		return false;
	}
}

this.coverflow = function(e, t) {
	$(t).click(function(){ $(this).addClass('on'); $(e).slideToggle('fast') })
}

this.objecttools = function(e, s){
	if( $(e).length && $(s).length ) {
		$(e).hover(
			function(){
				$(this).find(s).fadeIn(300)
			},
			function(){
				$(this).find(s).fadeOut(300)
			}
		).find(s).hide()
	}else{
		return false
	}
}

this.pub = function(e){
	if($(e).length) {
		$(e).find('li').height('222px').hover(
		function(){
			$(this).animate({height: '440px'}, 400, function(){ $(this).find('span').fadeOut('slow') })
		},
		function(){
			$(this).animate({height: '222px'}, 400, function(){ $(this).find('span').fadeIn('slow') })
		}
		
		)
	}else{
		return false
	}
}

this.search = function(e, t) {
	if ($(e).length && $(t).length) {
		$(t).click(function(){
			if( $(e).is('.on')) {
				$(e).animate({height: '25px'}, 300).removeClass('on')
			}else{
				$(e).animate({height: '395px'}, 300).addClass('on')
			}
		})
	}else{
		return false
	}
}


this.addtoscart = function( nart, qt ){
	$('#caddie div').load('/fr/shop/add2scart.html', {nart: nart, qt: qt } );
}
this.showscart = function(  ){
	$('#caddie div').load('/fr/shop/getMyScart.html', {ajax:1, output:'ajax'} );
}

$(document).ready(function(){
	pub('div#pubblock > ul')
	coverflow('div#coverflow', 'a.disp-coverflow')
	catshorts('div#prCats ul', 39)
	mainnav('div#bd div.left')
	// objecttools('ul#prListing li', 'span.tools')
	search('div#searchbar', 'fieldset#quicksearch a')
	
	if($('#highlight').length ) {
		swaper("#highlight", "60px");
	}
	
	// Cedric
	$('a.addtoscart').bind('click', function() { addtoscart( $(this).attr('href'), $('#qt-' + $(this).attr('href') ).val() ); return false } )
	$('a.trailer').bind('click', function(){ $('#trailer').slideToggle(); return false;})
	
	
})






