﻿//// functions
var hash = location.hash;

// Print Page
function PrintPage() {
    // remove vml
    $j("ignore").remove();
    window.print();
}



//// dom ready elements
$j(function () {
    //    $j('.equalheight .equal').equalHeight();

    // setup tooltip login portal
    $j("img.LoginPortalFormHelpIcon").each(
				function () {
				    myTitle = $j(this).attr("alt");
				    $j(this).attr("title", myTitle);
				}
		).tooltip({});

    // Setup KontaktSupport Spot Login Portal
    $j("#ButtonKontaktSupport").click(function () { $j("#ContentKontaktSupport").slideToggle() });


    // setup ul.tabs to work as tabs for each div directly under div.panes
    $j("#tvpage-subnav").tabs("div.pane");

    // initialize scrollable 
    $j("div.scrollable").scrollable({ next: ".nextPage", prev: ".prevPage", vertical: true }).mousewheel();

    // site search
    $j(".sitesearch input").focus(function () {
        $(this).removeClass("idleField").addClass("focusField");
        if (this.value == this.defaultValue) { this.value = ''; }
    });

    // initiate spotoverlay
    $j("a.SpotOverlay").livequery(function () {
        applySpotOverlay.call(this);
    });

    function applySpotOverlay() {
        $j(this).overlay({
            expose: "#000000",
            target: "#overlay",
            fixed: false,
            onBeforeLoad: function () {
                this.getOverlay().find(".contentWrap").html("");
                $j('#overlay').addClass("OverlaySpotOverlay");
                //this.getOverlay().append("<div class=\"SpotContent\"></div>");
                var wrap = this.getOverlay().find(".contentWrap");
                wrap.load(this.getTrigger().attr("href"));
            },
            onClose: function () {
                $j('#overlay').removeClass("SpotOverlay");
            }
        });
    }

    $j("map.SpotOverlay > area").each(function () {
        applySpotOverlay.call(this);
    });

    $j(function () {
        var $supportTipTip = $j(".support_tiptip");
        if ($supportTipTip.length) {
            $supportTipTip.tipTip();
        }
    });

    // initiate spotoverlayimage
    $j("a.SpotOverlayImage").livequery(function () {

        $j(this).overlay({
            expose: "#000000",
            target: "#overlay",
            fixed: false,
            onBeforeLoad: function () {
                this.getOverlay().find(".contentWrap").html("");
                $j('#overlay').addClass("OverlaySpotOverlayImage");
                var wrap = this.getOverlay().find(".contentWrap");
                wrap.append("<div class='box'><h2>" + this.getTrigger().attr('title') + "</h2></div>");
                wrap.append("<img src='" + this.getTrigger().attr('href') + "'>");
            },
            onClose: function () {
                $j('#overlay').removeClass("SpotOverlay");
            }
        });
    });

    /* Omniture spot tracking for normal spots*/
    $j('.Box a').not('.BoxArticle a,.panes a').click(
      function () {
          var spotTrackTitleh2 = $j(this).closest('.Box').find('h2').text();
          var s = s_gi(s_account);
          s.linkTrackVars = 'eVar12,events';
          s.linkTrackEvents = 'event12';
          s.eVar12 = document.location.pathname + " | " + spotTrackTitleh2 + " | (Spot)";
          s.events = 'event12';
          s.t();
      });

});


/***** FUNCTIONS RUN WHEN DOCUMENT READY *****/
$j(document).ready(function () {
    $j("div.packagesspots div.sectioncontent").equalHeight();

    $j('#faqpopup_right ul li h3 a').click(function () {
        $j(this).toggleClass('expanded');
        if ($j(this).hasClass('expanded')) {
            $j(this).css("background-image", "url('/img/faqpopup_right_icon_minus.gif')");
        }
        else {
            $j(this).css("background-image", "url('/img/faqpopup_right_icon_plus.gif')");
        }
    });

    $j('#faqpopup_right .collapse_link').click(function () {
        $j(this).parent('div').hide();
        $j(this).parent('div').parent('li').find('.expand_link').toggleClass('expanded').css("background-image", "url('/img/faqpopup_right_icon_plus.gif')");
    });

    $j('.faq_popup').click(function () {
        window.open("/tv/tv-pakker_og_kanaler/faqpopup", "faq", "width=700,height=500,location=no");
    });

    $j('.column25 .faq li a').live('click', function () {
        window.open($j(this).attr('href'), "faq", "width=700,height=500,location=no");
        return false;

    });

});

function openFAQ() {
    window.open("/tv/tv-pakker_og_kanaler/faqpopup", "faq", "width=700,height=500,location=no");
}

