//var IE6 = (navigator.userAgent.indexOf("MSIE 6") >= 0) ? true : false;
//if (IE6) {
//    window.location = '/Portals/_default/skins/kiadealer2011/IE6Blocker/index.html';
//};

$(document).ready(function() {
    //show external forms in fancy
    $(".actionlinks a.UCRTopener, a.service_btn, .contentText a.UCRTopener, #meta a.UCRTopener").fancybox({
        'autoScale': false,
        'type': 'iframe',
        'width': 650,
        'height': 650,
        'scrolling': 'no'

    });
    //show large content image in fancy
    $(".contentImage a").fancybox();
    //tabs for dealers contact
    //$("ul.tabs").tabs(".box_contact > div", { effect: 'fade' });
    //prepend span tag to contact image
    $(".shr").prepend("<span></span>");
    //prepend span tag to paragraph image
    $(".contentImage a").prepend("<span></span>");
    // remove image block from only text News
    $(".announcements .contentImage img[src='']").each(function() {
        $(this).parent().remove();
    });
    // remove a tag from without link News
    $(".announcements a.more[href='']").each(function () {
        $(this).remove();
    });
    // add links from HP for without links news
    $(".nul li a[href='']").each(function () {
        $(this).attr('href', '/O-nas/Aktuality.aspx');
    });
    //add FB link to HP News box
    if ($("#HiddenFieldFacebook").val() != undefined && $("#HiddenFieldFacebook").val().length) {
        $('.news').append($("<a href='" + $("#HiddenFieldFacebook").val() + "' target='_blank' class='newsFB' title='Facebook'>Facebook</a> "));
    }
    //add dealer ID to link to test drive form, brochure request and service order
    if ($("#HiddenFieldSubDealerIDs").val() != undefined && $("#HiddenFieldSubDealerIDs").val().length) {
        $("a[href='http://kiaforms2011.eurosoftworks.com/TestDrive.aspx?DealerID=#Dealer_code#']")
        .each(function()
        { 
            this.href = this.href.replace("#Dealer_code#", $("#HiddenFieldSubDealerIDs").val());
        });
        $("a[href='http://kiaforms2011.eurosoftworks.com/ServiceForm.aspx?DealerID=#Dealer_code#']")
        .each(function () {
            this.href = this.href.replace("#Dealer_code#", $("#HiddenFieldSubDealerIDs").val());
        });
        $("a[href='http://kiaforms2011.eurosoftworks.com/Brochures.aspx?DealerID=#Dealer_code#']")
        .each(function() {
            this.href = this.href.replace("#Dealer_code#", $("#HiddenFieldSubDealerIDs").val());
        });
    }
    // replace aphostrofe for cee'd
    $("#footerNavigation ul li span")
        .each(function() {
    $(this).html($(this).html().replace("'", "&#180;"));
        });
    // IE detection
    if ($.browser.msie) {
        $("body").addClass("isIE")
    }
    if ($.browser.msie && $.browser.version == "6.0") {
        var isIE6 = true;
        $("body").addClass("isIE6");
    }
    else { var isIE6 = false; }
    if ($.browser.msie && ($.browser.version == "7.0" || $.browser.version == "8.0")) {
        var isIE7andUp = true;
        $("body").addClass("isIE7andUp");
    }
    else { var isIE7andUp = false; }
    if (isIE7andUp) {
        /* add shadow-elements for IE7+. */
        $("#mainNavigation ul ul").each(function() {
            $(this).append($("<span />").addClass("subNavigationBottomLeft").html("&nbsp;"))
                   .append($("<span />").addClass("subNavigationBottomRight").html("&nbsp;"));
        });
        $("#mainNavigation ul ul").each(function() {
            $(this).append($("<span />").addClass("subNavigationTopLeft").html("&nbsp;"))
                   .append($("<span />").addClass("subNavigationTopRight").html("&nbsp;"));
        });
        $("#footerNavigation ul li:first-child").addClass("first-child");
        $("#footerNavigation ul li:last-child").addClass("last-child");
        $(".subNavigationModel").each(function() {
            $(this).append($("<span />").addClass("subNavigationBottomLeft").html("&nbsp;"))
                   .append($("<span />").addClass("subNavigationBottomRight").html("&nbsp;"));
        });
    }
});
