Cufon.replace('.cufon_light', {hover: true});



function news_listing_tab_slider(tab_to_show){
    switch(tab_to_show){
        case 'news':
            $(".first_slider").removeClass("slider_unselected");
            $(".second_slider").addClass("slider_unselected");
            $(".news_listing_slider_box1").css("visibility","visible");
            $(".news_listing_slider_box2").css("visibility","hidden");
            break;
        case 'commenti':
            $(".first_slider").addClass("slider_unselected");
            $(".second_slider").removeClass("slider_unselected");
            $(".news_listing_slider_box1").css("visibility","hidden");
            $(".news_listing_slider_box2").css("visibility","visible");
            break;
    }
}


function show_product_related_trade_items(){
    $(document).ready(function(){
        $("#box_right_cont").css("visibility",'visible');
    });
}


function redirect_form_registrazione(alternativeForm){
    var url = document.location.toString();
    if(url.indexOf("alternativeForm")==-1 && url.indexOf("?")==-1){
        // url completamente pulito
        url+= "?alternativeForm="+alternativeForm;
    }else if(url.indexOf("alternativeForm")!=-1){
        // url con già dentro il paramentro alternativeForm
        url = url.substr(0,url.indexOf("alternativeForm"))+"alternativeForm="+alternativeForm;
    }else{
        //  url con già un paramentro ma non alternative form
        url+= "&alternativeForm="+alternativeForm;
    }
    document.location = url;
    
}

if(document.location.toString().indexOf('showonlycontent=true')!=-1){
    $(document).ready(function(){
        $('.pheader').css('display', 'none');
        $('.pmenu').css('display', 'none');
        $('#box_right').css('display', 'none');
        $('#content_bottom').css('display', 'none');
        $('.pbreadcrumbs').css('display', 'none');
        $('#footer').css('display', 'none');
        $('.bottone_link').css('display', 'none');
        $('#product_listing').css('width', '750px');
    });
}


//   ---   CONTENT RATING   ---   //
function content_rating(vote){
    for(var i=1; i<=5; i++){
        if(i<=vote){
            //  Scheda prodotto
            if(document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneCenter_RatingDocument_ImageButtonStar'+i)){
                document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneCenter_RatingDocument_ImageButtonStar'+i).src = '../../../App_Themes/Nokia4u/Images/star_selected.png';
            }
            //  Scheda news
            if(document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContent_RatingDocument_ImageButtonStar'+i)){
                document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContent_RatingDocument_ImageButtonStar'+i).src = '../../App_Themes/Nokia4u/Images/star_selected.png';
            }
            //  Scheda trade
            if(document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContent_RatingDocumentTrade_ImageButtonStar'+i)){
                document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContent_RatingDocumentTrade_ImageButtonStar'+i).src = '../../../App_Themes/Nokia4u/Images/star_selected.png';
            }
            //  Blog post
            if(document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContentBottom_RatingDocument_ImageButtonStar'+i)){
                document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContentBottom_RatingDocument_ImageButtonStar'+i).src = '../../../../App_Themes/Nokia4u/Images/star_selected.png';
            }
            //  Content rating
            if(document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContent_RatingContent_ImageButtonStar'+i)){
                document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContent_RatingContent_ImageButtonStar'+i).src = '../../App_Themes/Nokia4u/Images/star_selected.png';
            }
        }else{
            //  Scheda prodotto
            if(document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneCenter_RatingDocument_ImageButtonStar'+i)){
                document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneCenter_RatingDocument_ImageButtonStar'+i).src = '../../../App_Themes/Nokia4u/Images/star_unselected.png';
            }
            //  Scheda news
            if(document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContent_RatingDocument_ImageButtonStar'+i)){
                document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContent_RatingDocument_ImageButtonStar'+i).src = '../../App_Themes/Nokia4u/Images/star_unselected.png';
            }
            //  Scheda trade
            if(document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContent_RatingDocumentTrade_ImageButtonStar'+i)){
                document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContent_RatingDocumentTrade_ImageButtonStar'+i).src = '../../../App_Themes/Nokia4u/Images/star_unselected.png';
            }
            //  Scheda post
            if(document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContentBottom_RatingDocument_ImageButtonStar'+i)){
                document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContentBottom_RatingDocument_ImageButtonStar'+i).src = '../../../../App_Themes/Nokia4u/Images/star_unselected.png';
            }
            //  Content rating
            if(document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContent_RatingContent_ImageButtonStar'+i)){
                document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContent_RatingContent_ImageButtonStar'+i).src = '../../App_Themes/Nokia4u/Images/star_unselected.png';
            }
        }
    }
}
function content_unrating(){
    for(var i=1; i<=5; i++){
        //  Scheda prodotto
        if(document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneCenter_RatingDocument_ImageButtonStar'+i)){
            document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneCenter_RatingDocument_ImageButtonStar'+i).src = '../../../App_Themes/Nokia4u/Images/star_unselected.png';
        }
        //  Scheda news
        if(document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContent_RatingDocument_ImageButtonStar'+i)){
            document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContent_RatingDocument_ImageButtonStar'+i).src = '../../../App_Themes/Nokia4u/Images/star_unselected.png';
        }
        //  Scheda trade
        if(document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContent_RatingDocumentTrade_ImageButtonStar'+i)){
            document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContent_RatingDocumentTrade_ImageButtonStar'+i).src = '../../../App_Themes/Nokia4u/Images/star_unselected.png';
        }
        //  Blog post
        if(document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContentBottom_RatingDocument_ImageButtonStar'+i)){
            document.getElementById('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneContentBottom_RatingDocument_ImageButtonStar'+i).src = '../../../../App_Themes/Nokia4u/Images/star_unselected.png';
        }
    }
}

//   ---   SLIDER SPALLA DESTRA PRODOTTI   ---   //
      $(document).ready(function(){
                $("#product_slider_news_video").easySlider({
                        auto: true,
                        numeric: true,
                        continuous: true,
                        numericId: 'controls_1',
                        numericClass: 'controls_sfondo'
                });
                $("#product_slider_news_no_video").easySlider({
                        auto: true,
                        numeric: true,
                        continuous: true,
                        numericId: 'controls_2',
                        numericClass: 'controls_sfondo'
                });				
				$("#product_slider_trade").easySlider({
                        auto: true,
                        numeric: true,
                        continuous: true,
                        numericId: 'controls_3',
                        numericClass: 'controls_sfondo'
                });								
      });


//   ---   SALES   ---   //
$(document).ready(function(){
    //  Box errori
    if(document.getElementById("form_error_box") && document.getElementById("form_error_box").innerHTML.replace(/^\s+|\s+$/g,"").length>0){
       document.getElementById("form_error_box").style.display = 'block' ;
    }
    //  Tooltip
    var offsetX = 35;
    var offsetY = 50;

    $("a.info").hover(function(e){
        this.t = this.title;
        this.r = this.rel
        var c = (this.t != "") ? this.t : "<img src='"+this.r+"'/>";
        $("body").append("<div id='hovertip-1'><div id='info_top'></div><div id='info_bottom'></div><div id='freccia'></div>"+"<p> "+ c +"</p></div>");
        $("#hovertip-1")
            .css("top",(e.pageY - offsetX) + "px")
            .css("left",(e.pageX + offsetY) + "px")
            .fadeIn("fast");
        },
        function(){
            this.title = this.t;
            $("#hovertip-1").remove();
            this.name= this.n;
            $("#hovertip-1").remove();
        });
        $("a.hovertip-1").mousemove(function(e){
            $("#hovertip-1")
                .css("top",(e.pageY - offsetX) + "px")
                .css("left",(e.pageX + offsetY) + "px");
        });
    });


var activeServiceID = null;
function ProductShowServiceDetails(serviceID){

    document.getElementById("product_rating").style.display = 'none';
    document.getElementById("variants").style.display = 'none';
    if(activeServiceID!=null){
        document.getElementById("serviceID_"+activeServiceID+"_details").style.display = 'none';
    }
    document.getElementById("serviceID_"+serviceID+"_details").style.display = 'block';
    document.getElementById("serviceID_"+serviceID+"_li").className = 'active';
    activeServiceID = serviceID;
}
function ProductHideServiceDetails(){
    document.getElementById("product_rating").style.display = 'block';
    document.getElementById("serviceID_"+activeServiceID+"_details").style.display = 'none';
    document.getElementById("serviceID_"+activeServiceID+"_li").className = 'normal';
    document.getElementById("variants").style.display = 'block';
}



/*  PRODUCT VARIANT */
var active_product_variant_id = null;
function ProductActivateVariant(variantID){

    var current_variant_id = null;


    if(active_product_variant_id==null){
        active_product_variant_id = variantID;
        document.getElementById("variant_selector_"+variantID).className = 'active';
        document.getElementById("variantbox"+variantID).style.visibility = 'visible';
    }

    jQuery( document ).ready( function(){
            jQuery( '#variant'+variantID ).jcoverflip({
              current: Math.round(jQuery( '#variant'+variantID ).find('li').length/2)-1,
                beforeCss: function( el, container, offset ){

                    if(offset>1){
                        var left_d = ( container.width( )/2- 125 - 70 );
						var opacity_el = 0;
                    }else{
                        var left_d = ( container.width( )/2- 125 - 70*(offset+1) );
						var opacity_el = 1;
                    }
                    var num_elements = container.find('li').length;

                    el.css("z-index", num_elements-offset)
                        return [
                                $.jcoverflip.animationElement( el, {left: left_d +'px', bottom: '30px'}, { } ),
                                $.jcoverflip.animationElement( el.find( 'img' ), {opacity: opacity_el, width: '125px'}, {0.5: {'z-index': '1'}} )
                        ];
                },
                afterCss: function( el, container, offset ){
                    if(offset>1){
                        var left_d = ( container.width( )/2 + 70);
						var opacity_el = 0;
                    }else{
                        var left_d = ( container.width( )/2 + 70*(offset+1));
						var opacity_el = 1;
                    }
                    var num_elements = container.find('li').length;
					
                    el.css("z-index", num_elements-offset)
                        return [
                                $.jcoverflip.animationElement( el, {left: left_d+'px', bottom: '30px'}, { } ),
                                $.jcoverflip.animationElement( el.find( 'img' ), {opacity: opacity_el, width: '125px'}, {0.5: {'z-index': '1'}} )
                        ];
                },
                currentCss: function( el, container ){
                        el.css("z-index", '100')
                        return [
                                $.jcoverflip.animationElement( el, {left: ( container.width( )/2 - 125 )+'px', bottom: 0}, { } ),
                                $.jcoverflip.animationElement( el.find( 'img' ), {opacity: 1, width: '250px'}, {1: {'z-index': '100'}} )
                        ];
                },

              controls: {
                  create: function(containerElement, length){

                    $("#nextButtonVariant"+variantID).click(function(){
                       $('#variant'+variantID).jcoverflip('next', 1, false);
                    });
                    $("#previousButtonVariant"+variantID).click(function(){
                       $('#variant'+variantID).jcoverflip('previous', 1, false);
                    });

                  },
                  destroy: function( containerElement ){
                  }

              }
            });

          });

}



function ProductChangeVariant(variantID){
    document.getElementById("variantbox"+active_product_variant_id).style.visibility = 'hidden';
    document.getElementById("variantbox"+variantID).style.visibility = 'visible';

    document.getElementById("variant_selector_"+active_product_variant_id).className = 'normal';
    document.getElementById("variant_selector_"+variantID).className = 'active';
    
    active_product_variant_id = variantID;
}
