﻿/// <reference path="~/lib/js/jquery-1.2.6-vsdoc.js" />

$(document).ready(function() {
    $.ajaxSetup({
        cache: true
    });

    /* Append pipe after each (except the last one) list item in the footer container div  */
    $("div#footerContainer ul > li:not(:last)").append("&nbsp;|");

    /* Append raquo after each (except the last one) list item in the bread crumb div  */
    $("div#breadCrumbContainer ul > li:not(:last)").append("&nbsp;&raquo;");

    /* Contact us should open in dialog */
    $("#Contacts--enquiries").click(function(event) {
        event.preventDefault();
        OpenContactLuvataDialog();
    });

    $("div#userInteractions a.contactUs").click(function() {
        OpenContactLuvataDialog();
    });

    $(".pStartPage div#contactContainer div#contactUs").click(function() {
        OpenContactLuvataDialog();
    });
    /* / Contact us should open in dialog */

    function OpenContactLuvataDialog() {
	OpenModalDialog(590, 765, '/tools/contact-luvata---dialog/', 'contactUsDialogContainer');
    }
    /* / Contact us 590 */


    /* execute when enter key is pushed  - two different search fields and buttons are used */
    var $btn = $("input[id$='_searchForm_btnSearch']");
    var $form = $btn.parents("#aspnetForm");

    $form.keypress(function(e) {
        if (e.which == 13 && (e.target.id.match("txtQuickSearch") != null)) {       /* make sure were typing in the search box */
            var buttonIndex = (e.target.id.match("MainRegion") == null ? 0 : 1);    /* First or second button (zero index) */
            if ($btn[buttonIndex].type == "image")
                $btn[buttonIndex].click();
            return false;
        }
    });

    /* modal dialog */
    function OpenModalDialog(width, height, url, div) {
	
	var pageId = $("input[id$='hfPageId']").val();
        var lang = $("input[id$='hfLang']").val();
	
        $("div#" + div).html("");


        $("div#" + div).load('/' + lang + url + '?pid=' + pageId).dialog({
	    height: width,
            width: height,
            modal: true,
            overlay: {
                opacity: 0.5,
                background: "black"
            },
            resizable: false,
            close: function() {
                window.location.reload();
            }
        });
    }
    /* modal dialog */

    /* Increase / decrease font size */
    $("#normal").click(function() {
        $("body").css("font-size", "75%");
    });

    $("#large").click(function() {
        $("body").css("font-size", "82%");
    });

    $("#larger").click(function() {
        $("body").css("font-size", "90%");
    });
    /* end Increase / decrease font size */

    /* E-mail this page should open in modal box */
    $("div#userInteractions a.emailPage").click(function() {
        OpenModalDialog(320, 450, '/tools/e-mail-this-page/', 'emailThisPageDialogContainer');
    });

    //Store Image paths 
    var toggleMinus = '/lib/styles/images/menu_minus.gif';
    var togglePlus = '/lib/styles/images/menu_plus.gif';

    var $subHead = $("li[class^='navExpanded']");
    var subMarked = $(".marked");

    $subHead.prepend('<img src="' + toggleMinus + '" alt="" /> ');

    /* Open / Close a branch */
    $('img', $subHead).addClass('clickable').click(function() {
        var toggleSrc = $(this).attr('src');
        if (toggleSrc == toggleMinus) {
            subMarked.removeClass('marked');
            $(this).attr('src', togglePlus).parent().children('ul').slideUp('normal', function() {
                subMarked.addClass('marked');
            });
        } else {
            subMarked.removeClass('marked');
            $(this).attr('src', toggleMinus).parent().children('ul').slideDown('normal', function() {
                subMarked.addClass('marked');
            });
        }
    });

    /* Create links between tabs */
    $('.pTabbedPage div#contentWrapper span.tabOne').click(function() {
        $(".pTabbedPage #contentContainer > ul#subPageSelector").tabs("select", 0);
    });
    $('.pTabbedPage div#contentWrapper span.tabTwo').click(function() {
        $(".pTabbedPage #contentContainer > ul#subPageSelector").tabs("select", 1);
    });
    $('.pTabbedPage div#contentWrapper span.tabThree').click(function() {
        $(".pTabbedPage #contentContainer > ul#subPageSelector").tabs("select", 2);
    });
    $('.pTabbedPage div#contentWrapper span.tabFour').click(function() {
        $(".pTabbedPage #contentContainer > ul#subPageSelector").tabs("select", 3);
    });
    /* Create links between tabs */

    /* Lightbox */
    $('div#luvata_image_gallery a').lightBox({ fixedNavigation: false });
    $('p.luvata_image_gallery a').lightBox({ fixedNavigation: false });
    /* Lightbox */

});
