/**
 * Document Ready
 */
$(document).ready(function(){
    //hide flags

    //$('#langs p a').each(function() {
    //    if($(this).attr("href") != "/") {
    //        $(this).hide();
    //    }
    //});
    
    /**
     * Fix som style on the top menu
     */
    $('#menu li:first').addClass("first");
    var currentpage = window.location.href;
    var path = window.location.path;
    //Iterate thru menu pages and check which matches
    $('#menu li a').each(function(){        
        if ($(this).attr("href") == currentpage || currentpage.indexOf($(this).attr("href")) > -1 || $(this).attr("href") == currentpage + "/") {
            $('#menu li a').each(function(){
                $(this).parent().removeClass("active");
            })
            $(this).parent().addClass("active");
        }
    });
    
    /**
     * Trim empty p-tags
     */
    $("p").filter( function() {
        return $.trim($(this).html()) == '';
    }).remove()
    $("p").filter( function() {
        return $.trim($(this).html()) == '&nbsp;';
    }).remove()
    
    /**
     * Manipulate the image in the teaser box depending on width and height
     */
    var img = $('.infobox .content img');    
    if ( img.width() > img.height() ) {
        img.after('<div style="clear:both;">&nbsp;</div>');
    }
    
    /**
     * Set open product box
     */
    if (window.location.href.indexOf('obturation') > -1) {
        $('#1 div').attr("style", "display:block;");
        $('#1').attr("class", "toplevel open");
    }
    if (window.location.href.indexOf('re-treatment') > -1) {
        $('#2 div').attr("style", "display:block;");
        $('#2').attr("class", "toplevel open");        
    }
    else if (window.location.href.indexOf('treatment') > -1) {
        $('#0 div').attr("style", "display:block;");
        $('#0').attr("class", "toplevel open");
    }    
    if (window.location.href.indexOf('sterilization') > -1) {
        $('#3 div').attr("style", "display:block;");
        $('#3').attr("class", "toplevel open");
    }
    $('#prodnav li div ul li a').each(function(){
       if ( $(this).attr("href") == window.location.href )
       {
            $(this).parent().addClass("active");
       }
    });
});

/**
 * Custom Functions
 */
function toggleProductDiv(divid) {
    //Close all open divs
    $('#prodnav li.toplevel').attr("class", "toplevel closed");
    $('#prodnav li div').slideUp();
    //Just fell out if it wasn't open
    if ($('#' + divid + ' div').css("display") == "block") {
        //
    } else {
        if(navigator.userAgent.indexOf("MSIE 7.0") > -1) 
            $('#' + divid + ' div').toggle();
        else        
            $('#' + divid + ' div').slideToggle();
        $('#' + divid + ' div').css("display", "block");
        $('#' + divid).attr("class", "toplevel open");
    }
}

function showClickedMovie(id) {
    var videoIframe = '<iframe class="videoIframe" src="http://player.vimeo.com/video/' + id + '" width="686" height="389" frameborder="0"></iframe>';
    $('#movie').html(videoIframe);
}

