// JavaScript Document

      $(function(){
        $("#framecenter input, #framecenter textarea, #framecenter select, #framecenter button").uniform();
      });
	  
	  
	  
	  if (!$.browser.msie) {
         
		 $('head').append("<link href='http://fonts.googleapis.com/css?family=Arimo:regular,italic,bold,bolditalic' rel='stylesheet' type='text/css'>");
	  
	  }
	  
	  
	  
	  
	  
	  
	  
	  
	  $(document).ready(function(){
								 
								 
								 
								 
								 
								 
								 
					/////////////////////////////// controllo user device ///////////////////////////			 
					var isiPad = navigator.userAgent.match(/iPad/i) != null;
					var isiPhone = navigator.userAgent.match(/iPhone/i) != null;
					var isiPod = navigator.userAgent.match(/iPod/i) != null;

								 
					if(isiPad){
					  $('head').append("<link href='http://www.vermontitalia.com/css/ipad-fixed.css' rel='stylesheet' type='text/css'>");	
					}
								 
								 
								 
								 
					////////////////// scheda prodotto toogle
					
					if($('.productdetails .productdetailstoogle').size()>1){
						
						var productDetailsHeader = $('<div class="product-details-header"></div>');
						$('.productdetails').prepend(productDetailsHeader);
						var tallest = 0;
						
						$('.productdetails .productdetailstoogle').each(function(index){
													
						
							var thisHeight = $(this).height();
							if(thisHeight > tallest) {
								tallest = thisHeight;
							}						
													
						   var texth3 = $('h3',this).html();
						   var a = $('<a href="javascript:void(0)" id="'+index+'">'+texth3+'</a>');

						   $(this).hide();
						   $('h3',this).hide();
						   
						   $(productDetailsHeader).append(a);
																				 
						});
						
						//$('.productdetails .productdetailstoogle').height(tallest);

						
						$('.productdetails .productdetailstoogle').eq(0).show();
						$('.product-details-header a').eq(0).addClass("active");
						
						if($('.product-details-header a').size()>4){
						  $('.product-details-header a').css("font-size","11px")
						  $('.product-details-header a').css("padding","4px 5px")
						}
						
						
						$('.product-details-header a').click(function(){
							
							var index = $(this).attr("id");
							$('.product-details-header a').removeClass('active');		
							$(this).addClass("active");
							$('.productdetails .productdetailstoogle').hide();
							$('.productdetails .productdetailstoogle').eq(index).fadeIn();
							
						});
						
						
					}
								 
							//alert($('.productdetails').html());	 
			
	
				
				
		if(document.getElementById("video_list_scroll")){
								 
								 
		$("#video_list_scroll").smoothDivScroll({ 
		   scrollStep: 5
		   /*scrollInterval: 5;
			 autoScroll: "onstart" , 
			autoScrollDirection: "backandforth", 
			autoScrollStep: 1, 
			autoScrollInterval: 15,	
			startAtElementId: "startAtMe", 
			visibleHotSpots: "always"*/
		});
		
		
		
		$("#video_list_scroll .scrollableArea a").click(function(){
		    
			var id_video = $(this).attr("id");
			var title_video = $(this).find('span').eq(0).html();
			$('#videoplayer iframe').remove();
			var iframe = $('<iframe></iframe>');
			var iframesrc = 'http://player.vimeo.com/video/'+id_video+'?byline=0&amp;portrait=0&amp;color=ffffff&amp;autoplay=1';
			$(iframe).attr("src",""+iframesrc+"");
			$(iframe).attr("width","700");
			$(iframe).attr("height","394");
			$(iframe).attr("frameborder","0");
			$('#videoplayer').prepend($(iframe));
			$('#videoplayer h3').html(title_video);
			
			/* src="http://player.vimeo.com/video/25969825?byline=0&amp;portrait=0&amp;color=ffffff&amp;autoplay=1" width="700" height="394" frameborder="0" */
			
		});		
		
		
		}
								 
								 
								 
								 
								 
								 
								 
								 
								 
								 
								 
								 
								 
					
					
					$("#boxformlogin a#openform").click(function(){
						$(this).css("display","none");
						$("#FormLogin").fadeIn();
				    });
					
					

					
					
					
					
					var newslength = $(".newstoogle").size();
					if(newslength>1){
						
					$(".newstoogle").not(':eq(0)').addClass("closed");
					
						$(".newstoogle").each(function(index){
													   
						   $("h3", this).attr("id",index);
						   
						   $("h3", this).click(function(){
								
								var index = $(this).attr("id");
								
                                $(".newstoogle").addClass("closed");
								$(".newstoogle").removeClass("open");
								$(".newstoogle").find("div").hide();
								
								var div = $(".newstoogle").eq(index).addClass("open");
								var divtoogle= $(div).find("div");
								var h = $(divtoogle).innerHeight();
								var marginIE = 0;
								
								if ($.browser.msie) {
								 marginIE = 40;	
								}

								
									$(divtoogle).css("height","1px").animate({
									height: (h+marginIE)+'px'}, 1000, function() { 
									
									 //$(divtoogle).css("height",(h-marginIE)+"px")
									
									});
								/*
								if($(divtoogle).hasClass("closed")){
									$(divtoogle).addClass("open");
									$(divtoogle).removeClass("closed");
									var h = $(divtoogle).innerHeight();
									$(divtoogle).css("height","1px").animate({
									height: h+'px'}, 1000, function() { });
								}else{
								    $(divtoogle).addClass("open");
								}*/
							

								//$(".newstoogle:not:eq(1)").find("div").addClass("closed").css("backgroundColor","#FFCC00");
								
							});
						   
						
						});
						
					}
					
					
					
        /*
        $(".overimage").hover(function() {
            $(this).fadeTo("slow", 0.6);
        }, function() {
            $(this).fadeTo("slow", 1.0);
        });
        */

		
		
		
		
		
		
	function utf8_encode (argString) {
    // http://kevin.vanzonneveld.net
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: sowberry
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman
    // +   improved by: Yves Sucaet
    // +   bugfixed by: Onno Marsman
    // +   bugfixed by: Ulrich
    // +   bugfixed by: Rafal Kukawski
    // *     example 1: utf8_encode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'

    if (argString === null || typeof argString === "undefined") {
        return "";
    }

    var string = (argString + ''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");
    var utftext = "",
        start, end, stringl = 0;

    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;

        if (c1 < 128) {
            end++;
        } else if (c1 > 127 && c1 < 2048) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc !== null) {
            if (end > start) {
                utftext += string.slice(start, end);
            }
            utftext += enc;
            start = end = n + 1;
        }
    }

    if (end > start) {
        utftext += string.slice(start, stringl);
    }

    return utftext;
}

		
		
		
		function utf8_decode (str_data) {
    // http://kevin.vanzonneveld.net
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +      input by: Aman Gupta
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Norman "zEh" Fuchs
    // +   bugfixed by: hitwork
    // +   bugfixed by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: utf8_decode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'
    var tmp_arr = [],
        i = 0,
        ac = 0,
        c1 = 0,
        c2 = 0,
        c3 = 0;

    str_data += '';

    while (i < str_data.length) {
        c1 = str_data.charCodeAt(i);
        if (c1 < 128) {
            tmp_arr[ac++] = String.fromCharCode(c1);
            i++;
        } else if (c1 > 191 && c1 < 224) {
            c2 = str_data.charCodeAt(i + 1);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str_data.charCodeAt(i + 1);
            c3 = str_data.charCodeAt(i + 2);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }

    return tmp_arr.join('');
}

		
		
		
					
					
					
								 
	  });
