
//PNG IE FIX
function preloadImages(id) {
    var c = new Array();
    $(id+' img').each( function(j) {
        c[j] = new Image();
        c[j].src = this.src;

        if ( $.browser.msie ) {
            this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='image',src='"+ this.src +"')"; 
        }
    });

}
preloadImages('#bodyAll');


// Toggle FADE
jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);

}; 

// PLAY&PAUSE
function controlla(){
                        var ctrl1 = niftyplayer('niftyPlayer1').getState();
                        if(ctrl1 == "paused"){niftyplayer('niftyPlayer1').play()}
                    }

var gotoPage = function(marginLeft, liID, opacity){
    $('#caruselWrapper').animate({
        scrollLeft : marginLeft
    },  900, 'easeInOutExpo', function(){
        $("#" + liID). animate({
            opacity: opacity
        }, 200);
        //hack fix all
        $(".bigCarusel li").css("opacity", 1);
    });                
	
    return false;
}

var initLayouts = function(){
    // adjust width fake :D // stupid thing
    var tempWidth = (($("body").width() - 900) / 2) - 50;
    $("#sectionfake").width(tempWidth);
    $("#sectionfake").css('padding','0px');
}

var servicesSlide = function(moveTo){
	
    $('.contentTextSlide').stop().animate({
        scrollTop : moveTo
    },  350, 'easeInOutExpo', function(){
		
        });
}
var galleryCarusel = function(action){
    var move = function(direction){
        var moveTo = 0;
        var stepSize = 900;
        var currentPos = $('.galleryCarusel').scrollLeft();
		
        var limitSize = (($(".imgSlideshow").size() / 3) * stepSize) - stepSize;
        if(direction == 'next'){
            if(currentPos < limitSize){
                moveTo = currentPos + stepSize;
            }else{
                moveTo = 0;
            }
        } else if(direction == 'prev'){
            if(currentPos > 0){
                moveTo = currentPos - stepSize;
            }else{
                moveTo = 0;
            }
        }
	
        $('.galleryCarusel').stop().animate({
            scrollLeft : moveTo
        },  1250, 'easeInOutExpo', function(){
			
            });
    } 
	
    if(action == 'next'){
        move('next');
    }else if(action == 'prev'){
        move('prev');
		
    }else{
        alert('act: ' + action + ' not bind');
    }
}

function str_replace (search, replace, subject, count) {
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
    f = [].concat(search),
    r = [].concat(replace),
    s = subject,
    ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }

    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;
            }
        }
    }
    return sa ? s : s[0];
}

var currentShow = '';
var currentClasa = '';
var caruselFilter = function(clasa){
    $(".imgSlideshow").css('display', 'none');
    currentClasa = clasa;
    currentShow += "," + clasa;
    $(currentShow).css('display', 'block');
	
$(".galleryMenu").animate({
		opacity : 0,
		bottom: '150px'
	}, {duration: 300, easing: 'easeOutBack'});
}

$(window).resize(function() {
    initLayouts();
});

$(document).ready(function(){
						   $('#hiddenCart').hide();		
    $(".bigCarusel li").css("opacity", 1);
    initLayouts();
//    autoSelect();
    var clickOpacity = 1;
	
    /*	$(".galleryMenu").css('opacity', 0);*/
    $(".categoriesBtn").click(function(){
        if($(".galleryMenu").css('opacity') == 0){
            $(".galleryMenu").animate({
                opacity : 1,
                bottom: '160px'
            }, {
                duration: 400, 
                easing: 'easeOutBack'
            });
        }else{
            $(".galleryMenu").animate({
                opacity : 0,
                bottom: '150px'
            }, {
                duration: 400, 
                easing: 'easeOutBack'
            });
        }
        return;
    });
	
    $("#sectionEvents a.galleryLightbox").fancybox({
        'titleShow'     : true,
        'transitionIn'	: 'elastic',
        'transitionOut'	: 'elastic',
			'autoDimensions' : 'false',
		'autoScale' : 'false',
        'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<div style="width=100%"><span id="fancybox-title-over"><div style="float: left; text-align: left;width: 200px;">'+ title + '</div ><div id="fix_fancy" style="text-align: right;float:right;width: 100px;">' +  (currentIndex + 1) + ' / ' + currentArray.length +'</div></span></div>';
		}

    });
    $("#sectionEvents a").fancybox({
        'titleShow'     : true,
        'transitionIn'	: 'elastic',
        'transitionOut'	: 'elastic',
		'autoDimensions' : 'false',
		'autoScale' : 'false',
		'width' : '700px'
       
		

    });
	$('.simpleCart_checkout').click(function(){ $('.waitShop').fadeIn(300);});
	$('#s1').click(function(){
							$('#hiddenCart').fadeIn('slow');
							});
	$('.simpleCart_empty').click(function(){
									$('#hiddenCart').fadeOut('slow');	  
										  });

		    $('#sectionGallery a.galleryLightbox, #sectionLimited a.galleryLightbox').click(function(){	
														  
            	var rel_image = $(this).attr("rel");  
				var price = $(this).attr("price"); 
				var name = $(this).attr("title"); 
				var type = $(this).attr("type"); 
				var cod = $(this).attr("cod"); 
				var content = $(this).attr("href");
				loadFancyBox(content, price, type, name, cod);
				$('#fancybox-wrap').css({    'margin-left': '131px'});
				
				
						return false;
			
			});
			
			function loadFancyBox(content, price, type, name, cod)
{
    jQuery.fancybox({
        href: content,
		 transitionIn	: 'elastic',
        transitionOut	: 'elastic',
		autoDimensions: true,
		autoScale: false,
		centerOnScroll: true,
		onCleanup : function(){ $('.cart').fadeOut('slow');},
		//onStart: function() { $('.cart').fadeIn('slow');},
	    onComplete: function(){
						 $('.cart').fadeIn('slow');
                  		/*$("#fancybox-wrap").delay(500).animate({'top': '10px'});*/
				 		$('.cart #price').html(price);
				 		$('.item_name_full').html(name);
						$('.item_name').html(cod);
						if(type == 'men'){ $('.item_Size').html('<option value="39">39</option><option value="40">40</option><option value="41">41</option><option value="42">42</option><option value="43">43</option><option value="44">44</option><option value="45">45</option>');}
					 	else if(type == 'all'){ $('.item_Size').html('<option value="36">36</option><option value="37">37</option><option value="38">38</option><option value="39">39</option><option value="40">40</option><option value="41>41</option><option value="42">42</option><option value="43">43</option><option value="44">44</option><option value="45">45</option>');} 
						else { $('.item_Size').html('<option value="36">36</option><option value="37">37</option><option value="38">38</option><option value="39">39</option><option value="40">40</option>');}
	               }
    });     
}
    
	
    $('.galleryMenu-row').click(function(){
        if($(this).find(".checkbox").hasClass('checkboxSelected')){
            $(this).find(".checkbox").removeClass('checkboxSelected');
            $(this).find(".checkbox").css('background-position', '0px -19px');
            var temcurrentShow = str_replace("," + currentClasa, "", currentShow);
            $(".imgSlideshow").css('display', 'block');
        //$(temcurrentShow).css('display', 'block');
        }
        $(this).find(".checkbox").addClass('checkboxSelected');
    });	
	
	$('.btn_next_set').click(function(){				  
				$('#set1_men').fadeToggle(function(){$('#set2_men').fadeToggle();});	
				
			/*	var_top = $(this).css(top);
				alert (var_top);
				if( var_top == 0){
				$(this).animate({ top : '50px'},400);
				} else{ $(this).animate({ top : '0px'},400); }*/
	});
	
	
    $('.menuservices ul li').click(function(){
        $(".menuservices a").removeClass('selected');
        $(this).find("a").addClass('selected');
    });
	
      
        
    $('#btnHome').click(function(){
           $('#home_subsection').fadeIn();
    $('#mi_subsection').fadeOut();
        var xpos = 1;
        gotoPage(0, 'sectionHome', clickOpacity);
        $("#Video_player").remove();
        $("#sub-gallery").customFadeOut('slow');
    });
   
   
   var $const_num = 1430;
   $('#btnGallery, #btnOnlineShop').click(function(){
        
       
        var xpos = 1;
        $("#Video_player").remove();
        gotoPage($const_num, 'sectionGallery', clickOpacity);
        $('#videoContent').css('display', 'none');
        $("#sub-gallery").customFadeIn('slow');

    });
    $('#btnStore').click(function(){
        var xpos = 1;
        gotoPage($const_num*2, 'sectionGallery', clickOpacity);
        $("#Video_player").remove();
        $("#sub-gallery").customFadeOut('slow');
    });
    
  
    $('#btnEvents, #link_events').click(function(){
		 $('#fancybox-wrap').css({    'margin-left': 'auto'});
        controlla();
        var xpos = 1;
        gotoPage($const_num*3, 'btnEvents', clickOpacity);
        $("#Video_player").remove();
        $("#sub-gallery").customFadeOut('slow');
    });
    $('#btnVideo').click(function(){
	
        gotoPage($const_num*4, 'btnVideo', clickOpacity);
        $("#sub-gallery").customFadeOut('slow');
        $("#videoContent").customFadeIn('slow');
        $('#videoContent').load('flash/Video_player.html');
	

    });
    $('#btnContacts').click(function(){
        gotoPage($const_num*5, 'sectionContacts', clickOpacity);
        $("#Video_player").remove();
        var xpos = 1;
        $("#sub-gallery").customFadeOut('slow');
    });
	  $('#btn_limited').click(function(){
        controlla();
        var xpos = 1;
        gotoPage($const_num*6, 'btn_limited', clickOpacity);
        $("#Video_player").remove();
        $("#sub-gallery").customFadeOut('slow');
    });
	
	 $('#btnFaceOn').click(function(){
        gotoPage($const_num*7, 'sectionContacts', clickOpacity);
        $("#Video_player").remove();
        var xpos = 1;
        $("#sub-gallery").customFadeOut('slow');
    });

}); 


    $('#madeinitaly').click(function(){
    //    $('#home_subsection').fadeToggle().pngFix( {blankgif: '../images/blank.gif'} );
    $('#home_subsection').fadeToggle();
    $('#mi_subsection').fadeToggle();
	 $('.btnToggle').fadeToggle();
    
});





//Custom js

jQuery(document).ready(function(){ 
	tfuse_custom_form();
});

function tfuse_custom_form(){ 
	var my_error;
	var url = jQuery("input[name=temp_url]").attr('value');
	jQuery("#send").bind("click", function(){
		
	my_error = false;
	jQuery(".ajax_form input, .ajax_form textarea, .ajax_form radio, .ajax_form select").each(function(i)
	{
				var surrounding_element = jQuery(this);
				var value 				= jQuery(this).attr("value"); 
				var check_for 			= jQuery(this).attr("id");
				var required 			= jQuery(this).hasClass("required"); 

				if(check_for == "email"){
					surrounding_element.removeClass("error valid");
					baseclases = surrounding_element.attr("class");
					if(!value.match(/^\w[\w|\.|\-]+@\w[\w|\.|\-]+\.[a-zA-Z]{2,4}$/)){
						surrounding_element.attr("class",baseclases).addClass("error");
						my_error = true;
					}else{
						surrounding_element.attr("class",baseclases).addClass("valid");	
					}
				}
				
				if(check_for == "message"){
					surrounding_element.removeClass("error valid");
					baseclases = surrounding_element.attr("class");
					if(value == "" || value == "Write your message..."){					
						surrounding_element.attr("class",baseclases).addClass("error");
						my_error = true;
					}else{
						surrounding_element.attr("class",baseclases).addClass("valid");	
					}
				}
				
				if(required && check_for != "email" && check_for != "message"){
					surrounding_element.removeClass("error valid");
					baseclases = surrounding_element.attr("class");
					if(value == ""){					
						surrounding_element.attr("class",baseclases).addClass("error");
						my_error = true;
					}else{
						surrounding_element.attr("class",baseclases).addClass("valid");	
					}
				}
				
				
			   if(jQuery(".ajax_form input, .ajax_form textarea, .ajax_form radio, .ajax_form select").length  == i+1){ 
					if(my_error == false){
						jQuery(".ajax_form").slideUp(400);
						
						var $datastring = "ajax=true";
						jQuery(".ajax_form input, .ajax_form textarea, .ajax_form radio, .ajax_form select").each(function(i)
						{
							var $name = jQuery(this).attr('name');	
							var $value = encodeURIComponent(jQuery(this).attr('value'));
							$datastring = $datastring + "&" + $name + "=" + $value;
						});
															
						
						jQuery(".ajax_form #send").fadeOut(100);	
						
						jQuery.ajax({
						   type: "POST",
						   url: url+"/sendmail.php",
						   data: $datastring,
						   success: function(response){
						   jQuery(".ajax_form").before("<div class='ajaxresponse' style='display: none;'></div>");
						   jQuery(".ajaxresponse").html(response).slideDown(400); 
						   jQuery(".ajax_form #send").fadeIn(400);
						   jQuery(".ajax_form input, .ajax_form textarea, .ajax_form radio, .ajax_form select").val("");
							   }
							});
						} 
				}
			   
			});
			return false;
	});
}



// NiftyPlayer
var FlashHelper =
{
	movieIsLoaded : function (theMovie)
	{
		if (typeof(theMovie) != "undefined") return theMovie.PercentLoaded() == 100;
		else return
		false;
  },

	getMovie : function (movieName)
	{
  	if (navigator.appName.indexOf ("Microsoft") !=-1) return window[movieName];
	  else return document[movieName];
	}
};

function niftyplayer(name)
{
	this.obj = FlashHelper.getMovie(name);

	if (!FlashHelper.movieIsLoaded(this.obj)) return;

	this.play = function () {
		this.obj.TCallLabel('/','play');
	};

	this.stop = function () {
		this.obj.TCallLabel('/','stop');
	};

	this.pause = function () {
		this.obj.TCallLabel('/','pause');
	};

	this.playToggle = function () {
		this.obj.TCallLabel('/','playToggle');
	};

	this.reset = function () {
		this.obj.TCallLabel('/','reset');
	};

	this.load = function (url) {
		this.obj.SetVariable('currentSong', url);
		this.obj.TCallLabel('/','load');
	};

	this.loadAndPlay = function (url) {
		this.load(url);
		this.play();
	};

	this.getState = function () {
		var ps = this.obj.GetVariable('playingState');
		var ls = this.obj.GetVariable('loadingState');

		// returns
		//   'empty' if no file is loaded
		//   'loading' if file is loading
		//   'playing' if user has pressed play AND file has loaded
		//   'stopped' if not empty and file is stopped
		//   'paused' if file is paused
		//   'finished' if file has finished playing
		//   'error' if an error occurred
		if (ps == 'playing')
			if (ls == 'loaded') return ps;
			else return ls;

		if (ps == 'stopped')
			if (ls == 'empty') return ls;
			if (ls == 'error') return ls;
			else return ps;

		return ps;

	};

	this.getPlayingState = function () {
		// returns 'playing', 'paused', 'stopped' or 'finished'
		return this.obj.GetVariable('playingState');
	};

	this.getLoadingState = function () {
		// returns 'empty', 'loading', 'loaded' or 'error'
		return this.obj.GetVariable('loadingState');
	};

	this.registerEvent = function (eventName, action) {
		// eventName is a string with one of the following values: onPlay, onStop, onPause, onError, onSongOver, onBufferingComplete, onBufferingStarted
		// action is a string with the javascript code to run.
		//
		// example: niftyplayer('niftyPlayer1').registerEvent('onPlay', 'alert("playing!")');

		this.obj.SetVariable(eventName, action);
	};

	return this;
}

