﻿

$(document).ready(function() {
    SetBigButtonStyles();    
    SetDefaultValueOnSearchField();
    SetThickboxOnLinkCollections();
    SetRoundCorners();
    StyleXForm();
    RegisterFontSizeChanger();
    
    if ($.browser.msie) {
        if(getInternetExplorerVersion() < 8.0){
            $('.contactInfo').css('margin-top','15px');
        }
    }
    
    
    if($("#subMenu").html()!=null){
        $("#mainText").css('float','left');
        $("#mainText").css('width','516px');
        
        
        if($(".introImage").html()!=null){
            $(".IntroText").css('width','340px');
        }
    }
    
    if ($.browser.msie){
        $(".IntroText").css('margin-top','10px');
    }
    
    if($("#productImage").html()!=null){
        $(".IntroText").css('width',520-($("#productImage").width()+30)+"px");
    }
        
    
    Cufon.replace('h1, #MainMenu a, .insurancetop, .insuranceinfo');


    if (getUrlParameter("debug")=="true")
    {
    var message = ["message", "test123"];
    PageMethod("/Templates/FrendeWeb/AjaxServices/ContactUsService.aspx", "Ping", message,
            function(msg) {
                alert(msg.d);
            },
            function(msg) {
                alert("Feil: " + msg.d);
            });
    }  


   

});





function getInternetExplorerVersion()

// Returns the version of Internet Explorer or a -1

// (indicating the use of another browser).

{

 var rv = -1; // Return value assumes failure.

 if (navigator.appName == 'Microsoft Internet Explorer')

 {

   var ua = navigator.userAgent;

   var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");

   if (re.exec(ua) != null)

     rv = parseFloat( RegExp.$1 );

 }

 return rv;

}


var originalFontSizes = {};
var fontsToChange;
function RegisterFontSizeChanger(){
   
    setOriginalSizes();
    
    $(".smallfont").click(function () { 
        ChangeToSmallFont();
    });
    
    $(".mediumfont").click(function () { 
      ChangeToMediumFont();
    });
    
    $(".largefont").click(function () { 
      ChangeToLargeFont();
    });

    
}

function setOriginalSizes(){
    fontsToChange = "p, h1, h2, h3, a, span, dt, dd";
    var i = 0;
    $(fontsToChange).each(function() {
        if($(this).css('font-size')!=null){
            originalFontSizes[i] = $(this).css('font-size');
        }
        i++;
    });
    if($.cookie("size")!=null){
        var name = $.cookie("size");
        if(name=="medium"){
            ChangeToMediumFont();
            return;
        }
        
        if(name=="large"){
            ChangeToLargeFont();
            return;
        }
    }

}

function ChangeToSmallFont(){
    var i = 0;
    $(fontsToChange).each(function() {
        if($(this).css('font-size')!=null){
            /*$(this).css('font-size', originalFontSizes[i]);*/
			$(this).animate({
				fontSize:  originalFontSizes[i]
			});
        }
        i++;
    });
    $.cookie("size", null, {path: '/'});

}


function ChangeToMediumFont(){
	
	var i = 0;
    $(fontsToChange).each(function() {
        if($(this).css('font-size')!=null){
            var currentFontSizeNum = parseFloat(originalFontSizes[i], 10);
            var newFontSize = currentFontSizeNum+2;
			$(this).animate({
				fontSize: newFontSize
			});
            
        }
        i++;
    });
    $.cookie("size", "medium", { expires: 7, path: '/' });

}

function ChangeToLargeFont(){
    var i = 0;
    $(fontsToChange).each(function() {
        if($(this).css('font-size')!=null){
            var currentFontSizeNum = parseFloat(originalFontSizes[i], 10);
            var newFontSize = currentFontSizeNum+4;
            $(this).animate({
				fontSize: newFontSize
			});
        }
        i++;
    });
    $.cookie("size", "large", { expires: 7,path: '/' });
}

function SetBigButtonStyles(){
    jQuery("span.bigButton").parent().addClass("bigButton");
}

function StyleButton(className){
   
   var submitText = jQuery("input."+className).val();
   $("input."+className).hide();
   $("input."+className).parent().append('<p><a href="#" class="'+className+'"><span class="'+className+'">'+submitText+'</span></a></p>');
   
   
   
   $("a."+className).click(function(){ 
        jQuery(".defaulttext").each(function() {
            if($(this).val()==$(this).attr('title')){
                $(this).val('');
            }
           
        }); 
       $("input."+className).click();
     }); 
}

function StyleXForm(){
   jQuery(".defaulttext").each(function() {
    $(this).defaultValue($(this).attr('title'));
   }); 
   
   
   StyleButton("bigButton");
   StyleButton("bigGreyButton");

   
   
   jQuery(".qtip").each(function() {
    var content = $(this).html();
    $(this).html('<img src="/Templates/FrendeWeb/Styles/Images/help.png" alt="" />');
    $(this).qtip({
        content: content, // Set the tooltip content to the current corner
               position: {
                  corner: {
                     tooltip: 'bottomRight', // Use the corner...
                     target: 'topLeft' // ...and opposite corner
                  }
               },
               style: {
                  background: '#D8D8D8',
                  color: '#000',
                  border: {
                     width: 5,
                     radius: 10,
                     color: '#D8D8D8'
                  },
                  padding: 10, 
                  textAlign: 'left',
                  tip:true
               }



    });
   }); 
   
   


}

function SetDefaultValueOnSearchField(){
    var txtSearchDefaultValue = $("#txtSearchDefaultValue").text();
    $(".txtSearch").defaultValue($.trim(txtSearchDefaultValue));
}

function SetRoundCorners(){
    $("#InsuranceTop").corner("top 3px");
    $("#InsuranceSend").corner("bottom 3px");
    $("td.insurancetop").corner("top 3px");
    $("td.insurancebottom").corner("bottom 3px");
    $(".FilesAndLinksTop").corner("top 3px");
    $(".FilesAndLinksBottom").corner("bottom 3px");
    $(".productGroupHeader").corner("top 3px");
    $(".productPromoHeader").corner("top 3px");
    $(".boxTop").corner("top 3px");
    
    $("#TB_iframeContent").corner("bottom 3px");
    
}


function SetThickboxOnLinkCollections(){
   
    jQuery(".linkCollection li a").each(function() {
        jQuery(this).addClass("thickbox");
        var options = "KeepThis=true&TB_iframe=true&height=400&width=600";
        var strUrl = jQuery(this).attr("href").toString();
        if(strUrl.indexOf('?')==-1){
            jQuery(this).attr("href",jQuery(this).attr("href")+"?"+options);
        }else{
            jQuery(this).attr("href",jQuery(this).attr("href")+"&"+options);
        }
    }); 
    tb_init('.linkCollection li a');
}