/**
 *	MDB ADDONS
 *	Author: PETER FRANZÈN | EMBRYO.SE
 *
 *	PLUGIN FOR PRODUCT VIEW
 *	
 *	
 */

// jqpanles examples
$(document).ready(function(){
var COOKIE_NAME = 'gender';
                var ADDITIONAL_COOKIE_NAME = 'additional';
                var options = { path: '/', expires: 10 };
if($.cookie(ADDITIONAL_COOKIE_NAME) == 'MEN')
      {
          genderMen();
      }
if($.cookie(ADDITIONAL_COOKIE_NAME) == 'WOMEN')
      {
          genderWomen();
      }
if($.cookie(ADDITIONAL_COOKIE_NAME) == 'ALL')
      {
          genderALL();
      }
if($.cookie(ADDITIONAL_COOKIE_NAME) == '')
      {
          genderALL();
      }
$("li.all").bind('click',function(){
    genderALL();
});
$("li.women").bind('click',function(){
    genderWomen();
});
$("li.men").bind('click',function(){
    genderMen();
});

jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);
};
/**
 * This plugin can be used in 4 ways, this is only 1. Make sure to check
 * the other 3 links as well to see all the Modes.
 */

jQuery(function( $ ){
	$('#summary').fadeIn('slow');

	/**
	 * All the functions below, are used to update the summary div
	 * That is not the objective of the plugin, the really important part
	 * is the one right below. The option placeholder, and threshold.
	 */
	$.preload( '#singleproduct .image img', {//the first argument is a selector to the images
		
        onRequest:request,
		onComplete:complete,
		onFinish:finish,
		placeholder:'typo3conf/ext/mdb/res/img/placeholder.jpg',//this is the really important option
		notFound:'typo3conf/ext/mdb/res/img/notfound.jpg',//optional image if an image wasn't found
		threshold: 6 //'2' is the default, how many at a time, to load.
	});

	function update( data ){
		$('#done').html( ''+data.done );
		$('#total').html( ''+data.total );
		$('#loaded').html( ''+data.loaded );
		$('#failed').html( ''+data.failed );
    
	};
	function complete( data ){
		update( data );
		$('#image-next').html( 'none' );//reset the "loading: xxxx"
		$('#image-loaded').html( data.image );
	};
	function request( data ){
		update( data );
		$('#image-next').html( data.image );//set the "loading: xxxx"
	};
	function finish(){//hide the summary
		//$('#summary').fadeOut('slow');
        $('#parent').fadeIn('slow');
	};
});


            $("#topselect li",this).bind('mouseover', function(){
                $("#bottomselect > li").removeClass("closed");
                $(this).addClass("open");
                $(".opend").hide();
                $("#def").hide();
                $("#bottomselect > li").removeClass("openfirst");
                $("#bottomselect > #"+this.id).fadeToggle();
                $("#bottomselect > #"+this.id).addClass("opend");     
            });
             $("#topselect li").bind('mouseout', function(){
                $(".opend").hide();
                $("#def").show();
            });
           

            var container = $('div.sliderGallery');
            var ul = $('ul', container);
            var itemsWidth = ul.innerWidth() - container.outerWidth();
            //$('.wrap').css({'overflow' : 'hidden', 'background-color' : 'yellow', 'float' : 'left'});     
            $('.slider', container).slider({
                min: 0,
                max: itemsWidth,
                handle: '.handle',
                stop: function (event, ui) {
                    ul.animate({'left' : ui.value * -1}, 500);
                },
                slide: function (event, ui) {
                    ul.css('left', ui.value * -1);
                }
            });
      

    //GENDER SELECT FUNCTION
 function genderALL(){
    $.cookie(ADDITIONAL_COOKIE_NAME, 'ALL', { expires: 10 });
    $('li.all').addClass("active");
    $('li.men').removeClass("active");
    $('li.women').removeClass("active");
    $("td.Women").show();
    $("td.Men").show();
}
function genderMen(){
    $.cookie(ADDITIONAL_COOKIE_NAME, 'MEN', { expires: 10 });
    $('li.men').addClass("active");
    $('li.all').removeClass("active");
    $('li.women').removeClass("active");
    $("td.Women").hide();
    $("td.Men").show();
}
function genderWomen(){
    $.cookie(ADDITIONAL_COOKIE_NAME, 'WOMEN', { expires: 10 });
    $('li.women').addClass("active");
    $('li.all').removeClass("active");
    $('li.men').removeClass("active");
    $("td.Men").hide();
    $("td.Women").show();
}



});


