/*custom fadeTo including IE8 opacity/cleartype fix - see http://blog.bmn.name/2008/03/jquery-fadeinfadeout-ie-cleartype-glitch/comment-page-2/#comment-368*/
jQuery.fn.fadeTo = function(speed,to,callback) {
    return this.animate({opacity: to}, speed, function() {
        if (to == 1 && jQuery.browser.msie)
            this.style.removeAttribute('filter');

        if (jQuery.isFunction(callback))
            callback();
    });
};

$(document).ready(function() {
    Cufon.replace('h1'); 
    Cufon.replace('h2'); 
	//animate in all h1, h2 elements with visibility hidden via css .jsactive rules. This enables smoother transitions and reduces chance of FOUC
	$("h1, h2").css({"visibility": "visible"}).fadeIn();
	
	/*animate back to top and comment reply scroll links*/
	$("p#backtotop a").click(function(){
		$.scrollTo($(this).attr("href"), 800);
		return false;
	});
	$(".respond").click(function(){
		$.scrollTo($(this).attr("href"), 800);
		return false;
	});
	
	//superfish menu - see http://users.tpg.com.au/j_birch/plugins/superfish/
	$('#primarynav').supersubs({ 
            minWidth:    12,   // minimum width of sub-menus in em units 
            maxWidth:    27,   // maximum width of sub-menus in em units 
            extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish({							   
								delay:       200,                            // one second delay on mouseout 
								animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
								speed:       50,
								dropShadows: false
				});

	//trigger overlabel for search and contact form		
	//$("#header label, #hp-bottom-col1 label,#hp-bottom-col2 label, #content-contactfieldset label, #comment-contactfieldset label").overlabel();	
	
	
$('#modalMessage').dialog({ autoOpen: false });



}); //ends on load script

function setUpAnythingSlider() {
    $('.anythingSlider').anythingSlider({
        easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
        autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
        delay: 7000,                    // How long between slide transitions in AutoPlay mode
        startStopped: false,            // If autoPlay is on, this can force it to start stopped
        animationTime: 1500,             // How long the slide transition takes
        hashTags: true,                 // Should links change the hashtag in the URL?
        buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
        pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
        startText: "Start",                // Start text
        stopText: "Stopp",               // Stop text
        navigationFormatter: formatText // Details at the top of the file on this use (advanced use)
    });

    $("#slide-jump").click(function () {
        $('.anythingSlider').anythingSlider();
    });

    function formatText(index, panel) {
        return index + "";
    };
}

function contactBegin() {
    $('#hp-bottom-col1').fadeTo('slow', 0.1);
}

function contactSucess() {
    $('#hp-bottom-col1').fadeTo('slow', 1);
    $('#modalMessage').empty().append('Meddelande skickat, vi återkommer så fort vi kan.');
    $('#modalMessage').dialog({ autoOpen: true, modal: true, title: 'Meddelande', show: 'blind', hide: 'blind' });
}

function contactFailure() {
    $('#modalMessage').empty().append('Misslyckad sänding av meddelande, vänligen kontakta oss per telefon eller via mail. Felet är loggat och kommer åtgärdas');
    $('#modalMessage').dialog({ autoOpen: true, modal: true, title: 'Meddelande', show: 'blind', hide: 'blind' });
}

function newsletterBegin() {
    $('#hp-bottom-col2').fadeTo('slow', 0.1);
}

function newsletterSucess() {
    $('#hp-bottom-col2').fadeTo('slow', 1);
    $('#modalMessage').empty().append('Du är nu prenumerant av vårt nyhetsbrev.');
    $('#modalMessage').dialog({ autoOpen: true, modal: true, title: 'Meddelande', show: 'blind', hide: 'blind' });
}

function newsletterFailure() {
    $('#modalMessage').empty().append('Misslyckad aktivering av prenumeration, vänligen maila oss dina kontakt uppgifter så kommer vi manuellt att lägga till er till som nyhetsbrev prenumerant. Felet är loggat och kommer åtgärdas.');
    $('#modalMessage').dialog({ autoOpen: true, modal: true, title: 'Meddelande', show: 'blind', hide: 'blind' });
}

