(function($){
 $.fn.extend({

 	customStyle : function(options) {
	  if(!$.browser.msie || ($.browser.msie&&$.browser.version>5)){
	  return this.each(function() {
			var _this=this;
			var currentSelected = $(this).find(':selected');
			//create the list options
				var newList='<div class="customOptionsList"><div class="arrowTop"></div>';
				newList+='<li class="cSel"><a href="#" rel="'+currentSelected.val()+'">'+currentSelected.text()+'</a></li>';
				newList+='<ul id="listDom">';
				$("."+this.className+" option").each(function()
				{
					//$(this).css({display:'none'});
					//if($(this).val()!=currentSelected.val()){
				    	newList+='<li><a href="javascript:void(0)" rel="'+$(this).val()+'">'+$(this).text()+'</a></li>';
				    //}
				});
				newList+='</ul></div>';



			$(this).after('<div class="customStyleSelectBox"><div class="customStyleSelectBoxInner">'+currentSelected.text()+'</div></div>').css({position:'absolute',zIndex:-1, opacity:0,fontSize:$(this).next().css('font-size')});
			var selectBoxSpan = $(this).next();
			var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));
			var selectBoxSpanInner = selectBoxSpan.find(':first-child');
			selectBoxSpan.css({display:'inline-block'});
			selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
			var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
			$(this).height(selectBoxHeight).change(function(){
				// selectBoxSpanInner.text($(this).val()).parent().addClass('changed');   This was not ideal
			selectBoxSpanInner.text($(this).find(':selected').text()).parent().addClass('changed');
				// Thanks to Juarez Filho & PaddyMurphy
			});
			//add list options
			$("."+this.className).parent().append(newList);
			//$("body").append(newList);

			$(".customStyleSelectBox").click(function(){

				var p=$(_this).position();
				$('.customOptionsList').css({display:'block',left:p.left+'px',top:(p.top+20)+'px'});
				//this.next(newList).css({display:'block'});
				$(function()
				{
					// this initialises the demo scollpanes on the page.
					$('#listDom').jScrollPane();

				});
			});
			$(".customOptionsList li").click(function(){
				var sv=$(this).find("a").attr("rel");
				//$(".mySelectBoxClass").val(sv);
				$(_this).val(sv);
				$('.customOptionsList').css({display:'none'});
				$('.customStyleSelectBoxInner').html($(_this).find(':selected').text());
				//change the options list
				var currentSelected2 = $(_this).find(':selected');

				$(".cSel").html('<a href="#" rel="'+currentSelected2.val()+'">'+currentSelected2.text()+'</a>');

			});


	  });
	  }
	}

 });
})(jQuery);

(function($){
 $.fn.extend({

 	customStyle2 : function(options) {
	  if(!$.browser.msie || ($.browser.msie&&$.browser.version>5)){
	  return this.each(function() {
			var _this=this;
			var currentSelected = $(this).find(':selected');
			//create the list options
				var newList='<div class="customOptionsList"><div class="arrowTop"></div>';
				newList+='<li class="cSel"><a href="#" rel="'+currentSelected.val()+'">Seleziona Tipologia</a></li>';
				newList+='<ul id="listDom">';
				$("."+this.className+" option").each(function()
				{
					//$(this).css({display:'none'});
					//if($(this).val()!=currentSelected.val()){
				    	newList+='<li><a href="javascript:void(0)" rel="'+$(this).val()+'">'+$(this).text()+'</a></li>';
				    //}
				});
				newList+='</ul></div>';



			$(this).after('<div class="inputC4"><div class="customStyleSelectBoxInner2">'+currentSelected.text()+'</div></div>').css({position:'absolute',zIndex:-1, opacity:0,fontSize:$(this).next().css('font-size')});
			var selectBoxSpan = $(this).next();
			var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));
			var selectBoxSpanInner = selectBoxSpan.find(':first-child');
			selectBoxSpan.css({display:'inline-block'});
			selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
			var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
			$(this).height(selectBoxHeight).change(function(){
				// selectBoxSpanInner.text($(this).val()).parent().addClass('changed');   This was not ideal
			selectBoxSpanInner.text($(this).find(':selected').text()).parent().addClass('changed');
				// Thanks to Juarez Filho & PaddyMurphy
			});
			//add list options
			$("."+this.className).parent().append(newList);
			//$("body").append(newList);

			$("div.inputC4").click(function(){

				var p=$(_this).position();
				$('.customOptionsList').css({display:'block',left:p.left+'px',top:(p.top+20)+'px'});
				//this.next(newList).css({display:'block'});

			});
			$(".customOptionsList li").click(function(){
				var sv=$(this).find("a").attr("rel");
				//$(".mySelectBoxClass").val(sv);
				$(_this).val(sv);
				$('.customOptionsList').css({display:'none'});
				$('.customStyleSelectBoxInner2').html($(_this).find(':selected').text());
				//change the options list
				//var currentSelected2 = $(_this).find(':selected');

				//$(".cSel").html('<a href="#" rel="'+currentSelected2.val()+'">'+currentSelected2.text()+'</a>');

			});


	  });
	  }
	}

 });
})(jQuery);


(function($) {
	$.fn.custCheckBox = function(options){

		var defaults = {
				disable_all:	false,				//disables all the elements
				hover:	false,						//adds a hover state to the tag
				wrapperclass:	"group",			//the class name of the wrapper tag
				callback:	function(){}			//a click event call back
			};
		//override defaults
		var opts = $.extend(defaults, options);

		return this.each(function() {
	 		 var obj = $(this);

		$.fn.buildbox = function(thisElm){

			$(thisElm).css({display:"none"}).before("<span class=\"cust_checkbox\">&nbsp;&nbsp;&nbsp;&nbsp;</span>");

			var isChecked = $(thisElm).attr("checked");
			var boxtype = $(thisElm).attr("type");
			var disabled = $(thisElm).attr("disabled");

			if(boxtype === "checkbox")
			{
				$(thisElm).prev("span").addClass("checkbox");
				if(disabled || opts.disable_all){boxtype = "checkbox_disabled";}
			}
			else
			{
				$(thisElm).prev("span").addClass("radio");
				if(disabled || opts.disable_all){boxtype = "radio_disabled";}
			}

			if(isChecked)
				$(thisElm).prev("span").addClass("cust_"+boxtype+"_on");
			else
				$(thisElm).prev("span").addClass("cust_"+boxtype+"_off");

			if(opts.disable_all)
				$(thisElm).attr("disabled","disabled");


			//attach a click event for each label.

			$(thisElm).prev("span").prev("label").unbind().click(function(){

				if(!opts.disable_all)
				{
					var custbox = $(this).next("span");
					var boxtype = $(custbox).next("input").attr("type");
					var disabled = $(custbox).next("input").attr("disabled");

					if($(custbox).hasClass("checkbox"))
					{
						if($(custbox).hasClass("cust_"+boxtype+"_off") && !disabled)
						{
							$(custbox).removeClass("cust_"+boxtype+"_off").addClass("cust_"+boxtype+"_on").next("input").attr("checked","checked"); //turn on
						}

						else if(!disabled)
						{
							$(custbox).removeClass("cust_"+boxtype+"_on").addClass("cust_"+boxtype+"_off").next("input").removeAttr("checked"); //turn off
							$(custbox).removeClass("cust_"+boxtype+"_hvr");
						}


					}
					else if(!disabled)
					{
						$(custbox).parent().find(".cust_checkbox").removeClass("cust_"+boxtype+"_on").addClass("cust_"+boxtype+"_off").next("input").removeAttr("checked");
						$(custbox).removeClass("cust_"+boxtype+"_off").addClass("cust_"+boxtype+"_on").next("input").attr("checked","checked"); //turn on
						$(custbox).removeClass("cust_"+boxtype+"_hvr");
					}

					opts.callback.call(this);

				}

			}).hover(function(){
				var custbox = $(this).next("span");
				if($(custbox).hasClass("cust_checkbox_on") && opts.hover)
					$(custbox).addClass("cust_checkbox_hvr");
				else if($(custbox).hasClass("cust_radio_on") && opts.hover)
					$(custbox).addClass("cust_radio_hvr");

			},function(){
				var custbox = $(this).next("span");
				if($(custbox).hasClass("cust_checkbox_on") && opts.hover)
					$(custbox).removeClass("cust_checkbox_hvr");
				else if($(custbox).hasClass("cust_radio_on") && opts.hover)
					$(custbox).removeClass("cust_radio_hvr");

			});

			//attach a click event for each checkbox.
			$(thisElm).prev("span").unbind().click(function(){

				if(!opts.disable_all)
				{
					var boxtype = $(this).next("input").attr("type");
					var disabled = $(this).next("input").attr("disabled");

					if($(this).hasClass("checkbox"))
					{
						if($(this).hasClass("cust_"+boxtype+"_off") && !disabled)
							$(this).removeClass("cust_"+boxtype+"_off").addClass("cust_"+boxtype+"_on").next("input").attr("checked","checked"); //turn on
						else if(!disabled)
						{
							$(this).removeClass("cust_"+boxtype+"_on").addClass("cust_"+boxtype+"_off").next("input").removeAttr("checked"); //turn off
							$(this).removeClass("cust_"+boxtype+"_hvr");
						}
					}
					else if(!disabled)
					{
						$(this).parent().find(".cust_checkbox").removeClass("cust_"+boxtype+"_on").addClass("cust_"+boxtype+"_off").next("input").removeAttr("checked");
						$(this).removeClass("cust_"+boxtype+"_off").addClass("cust_"+boxtype+"_on").next("input").attr("checked","checked"); //turn on
					}

					opts.callback.call(this);

				}
			}).hover(function(){
				if($(this).hasClass("cust_checkbox_on") && opts.hover)
					$(this).addClass("cust_checkbox_hvr");
				else if($(this).hasClass("cust_radio_on") && opts.hover)
					$(this).addClass("cust_radio_hvr");
			},function(){
				if($(this).hasClass("cust_checkbox_on") && opts.hover)
					$(this).removeClass("cust_checkbox_hvr");
				else if($(this).hasClass("cust_radio_on") && opts.hover)
					$(this).removeClass("cust_radio_hvr");
			});

		};

		//build the boxes
		$.fn.buildbox($(obj));




	});
};

})(jQuery);
var cid=0;
var autoplay=1;
var animateTime=1000;
var autoplayTime=8000;
(function($){
 $.fn.extend({
	mbfScroller : function() {

	$(".top_im_det").html($(".items").find("div").html());

	$(".staff_next_img").click(function(){
		var listitems=$(".items").children("div.item");
		if(cid+1>=listitems.length){
			var nextid=0;
		}else{
			var nextid=cid+1;
		}

		$(".top_im_det").animate({opacity: 0.0}, animateTime,function(){$(".top_im_det").html($(".items").find("div.item").eq(nextid).html()).animate({opacity: 1}, animateTime)});
		cid=nextid;

	});
	$(".staff_prev_img").click(function(){
		var listitems=$(".items").children("div.item");
		if(cid-1<0){
			var nextid=listitems.length-1;
		}else{
			var nextid=cid-1;
		}

		$(".top_im_det").animate({opacity: 0.0}, animateTime,function(){$(".top_im_det").html($(".items").find("div.item").eq(nextid).html()).animate({opacity: 1}, animateTime)});
		cid=nextid;

	});
	$(".top_im_det").mouseenter(function(){
		autoplay=0;
	});
	$(".top_im_det").mouseleave(function(){
		autoplay=1;
	});

	$(".staff_next_img").mouseenter(function(){
		autoplay=0;
	});
	$(".staff_next_img").mouseleave(function(){
		autoplay=1;
	});
	$(".staff_prev_img").mouseenter(function(){
		autoplay=0;
	});
	$(".staff_prev_img").mouseleave(function(){
		autoplay=1;
	});

	setInterval('if(autoplay==1){$(".next").click();}',autoplayTime);
	}

 });
})(jQuery);



$(document).ready(function(){
	//$('.mySelectBoxClass').customStyle();
	//$('.mySelectBoxClass2').customStyle2();
	$('.top_im_det').mbfScroller();
});
