/*!
 * Jquery Persol Accordion v1.0
 *
 * Copyright 2010, Neticon S.R.L.
 * http://www.neticon.it
 *
 * Licensed to:
 * http://www.persol.com
 *
 * @author Riccardo Palazzo riccardo.palazzo(at)gmail(dot)com
 * @version 1.0.0
 *
 * Date: Dec 03 12:33:48 2010
 */
//**************************************************************************************************************************

////////////////////////////////////////////////
/////////// FUNCTIONS //////////////////////////
////////////////////////////////////////////////
//
 // ^^^^^^^^^^^^^^ WRAP HTML VARS ^^^^^^^^^^^^^^^^^^^^ //

$.fn.showPartialPositioning = function (first, last) {

    $().hiliteOff();

    $("#" + current_open + " .bgimage").stop().animate({ 'backgroundPosition': '' + (0 - bg_shift) + 'px 0px' }, 1000, "swing");
    $(".item").each(function (index, length) {

        var lo_z = (10 * (index + 1))
        var vel = parseInt((stage_width - (gap * item_tot)) + (gap * index));

        $(this).css("width", item_width + "px");
        $(this).css("z-index", lo_z);


        var range = (last - first + 1);
        var step = ((stage_width - (gap * (item_tot - range))) / range);

        if (index == 0 || index <= first) {
            avanzo = gap * index;
        } else if (index > first && index <= last) {
            /*
            if (index == 1)
                avanzo = avanzo + step - (10 * (item_tot - 1));
            else if (index == 2)
                avanzo = avanzo + step + (20 * (item_tot - 1));
            else
            */
                avanzo = avanzo + step;

        } else if (index > last) {
            avanzo = stage_width - (gap * (item_tot - index));
        }

        //alert(index + " " + avanzo);

        $(this).stop().animate({ "left": "" + (avanzo) + "px" }, vel, "swing");

    });
};
 
 

// turn off all red thumbs border
  
$.fn.accordPosition = function(total,pressed,oldest) {

    $(total).each(function(index) {
		  //$(this).toggleClass("sel_item").addClass("desel_item");
		  //alert(total +" - "+pressed+" - "+index);
		 var io=this
		 var mia_pos=(gap*index);
		 var easing_speed=500;
		 //var vel= parseInt(500+((item_tot-index)*200));
		  
					if (index <= pressed) {
						//
						 var mia_pos=(gap*index);
					} else {
						 // set the price of current accessory
						 var mia_pos=parseInt((stage_width-(gap*item_tot))+(gap*index));
					}
				  
				  	$("#"+pressed+" .bgimage").stop().animate({'backgroundPosition': '0px 0px'},1000,"swing");
				 
						if (oldest < index) {
							var easing_speed= parseInt(((gap*item_tot))+(gap*index))*3.5;
						} else {
							var easing_speed= parseInt(((gap*item_tot))+(gap*(item_tot-index)))*3.5;
						}	
						
				    $(this).stop().animate({"left": ""+(mia_pos)+""}, easing_speed,"swing",
								
								function() {
									if (index == pressed) {
										$().openCorpus(index);
									} else {
										$().closeCorpus(index);
									}
								}
																					 
					);

	 });

};
 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
$.fn.openCorpus = function(who) {
	//open the corpus text box
		var item_to_move="#"+who+" .corpus";
		$(item_to_move).stop().animate({"bottom": "20px"},300,"swing",
				//animate arrow
				function() {
  					$().moveArrow(who);
 				 }
  );
};

$.fn.closeCorpus = function(who) {
	//if (who == curr_open) {
		var item_to_move="#"+who+" .corpus";
		$(item_to_move).stop().animate({"bottom": "-130px"},300,"swing");
	//
};
$.fn.moveArrow = function(who) {
	//if (who == curr_open) {
        /*
		var item_to_move="#"+who+" .corpus_box img";
		var times=3;
		var times_count=0;
		//
		$(item_to_move).stop().animate({"top": ""+(15)+"px"},600,"swing",
				function() {
					$(item_to_move).animate({"top": "0px"},600,"swing");
				}
		);
        */
};

$.fn.hiliteSelected = function(who) {
  //turn off all red thumbs border
	$(".inner_bar").each(function(index) {
		$(this).toggleClass("active", false).addClass("inactive");
	});
	//turn on only the selected one
	$(who).toggleClass("active", true);
};
$.fn.hiliteOff = function() {	
	$(".inner_bar").each(function(index) {
		$(this).toggleClass("active", false).addClass("inactive");
	});
};
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //

var gap = 20;
var current_open = undefined;
var stage_width = 960;
var stage_heigth = 460
var item_tot = 6;
var item_width = parseInt(stage_width - (gap * item_tot)) + gap;
var bg_shift = 150;

$.fn.Configurator = function (o) {
    gap = 20;
    current_open = o.current_open;
    stage_width = 960;
    stage_heigth = 460
    item_tot = 6;
    item_width = parseInt(stage_width - (gap * item_tot)) + gap;
    bg_shift = 150;
};
