/// <reference path="jquery-1.5.1-vsdoc.js" />
/// <reference path="jquery-1.5.1.min.js" />

$(window).load(function () {

    var theWindow = $(window),
            $bg = $("#bg"),
            aspectRatio = $bg.width() / $bg.height();

    function resizeBg() {

        if ((theWindow.width() / theWindow.height()) < aspectRatio) {
            $bg
                        .removeClass()
                        .addClass('bgheight');
        } else {
            $bg
                        .removeClass()
                        .addClass('bgwidth');
        }

    }

    theWindow.resize(function () {
        resizeBg();
    }).trigger("resize");

});

$(document).ready(function () {

    var url = $(location).attr('href');
    var UrlElements = new Array();
    UrlElements = url.split('/')
    var Index = UrlElements.length - 1;
    var selctedmenuitem = UrlElements[Index].toLowerCase();

    // add scrollbars to content div
    $('.contentbody').jScrollPane({ showArrows: true });

    //make lightbox work
    $('.tourismmap a').lightBox();
    $('.contentgallery a').lightBox();


    //ipad background code
    //    if ((navigator.userAgent.indexOf('iPad') != -1) ||
    //        (navigator.userAgent.indexOf('iPod') != -1) ||
    //        (navigator.userAgent.indexOf('iPhone') != -1)) {

    //        var url = $("#bg").attr('src');
    //        $("#bg").append("<img id='mobilebg' src='' />");
    //        $("#bg").attr("src", url);

    //        $("#container").css("background", " #fff url('Content/background/home.jpg') no-repeat left");
    //        $("#bg").remove();
    //        $("#container").css("width", "1270");
    //        $("#container").css("top", "50%");
    //        $("#container").css("margin-top", "-302px");
    //    }


    //iphone redirect
    if (UrlElements[3].length == 0) {
        if ((navigator.userAgent.indexOf('iPhone') != -1) ||
					(navigator.userAgent.indexOf('iPod') != -1)) {
            document.location = 'http://www.bluestonerestaurant.com.au/mobile/';
        }
    }

    // add blank image to nav to prepare for when line is to be shown
    $('.line').each(function () {
        $(this).prepend("<img id='lineimg' src='Content/other/main-nav-blank.gif' width='40' />");
    });

    if (selctedmenuitem.toLowerCase() == "")
        selctedmenuitem = "about";

    if (selctedmenuitem.toLowerCase() == "melbourne")
        selctedmenuitem = "about";

    if (selctedmenuitem.length > 0) {
        //select main nav elements
        var isfoundsubnav = false;
        

        $(".navigation .mainnav").each(function () {
            //alert('main');
            if ($(this).attr('rel') != "") {
                if ($(this).attr('rel') == selctedmenuitem.toLowerCase()) { // selects the mainnav and performs below functions
                    $(this).prepend("<img id='lineimg' src='Content/other/main-nav-line.jpg' width='40' />"); // add line image left of current mainnav
                    $(this).css("margin-left", "-40px"); // move left 40px to allow for width of line.jpg
                    $(this).css("color", "#666"); // change color of selected mainnav
                    $(this).parent().find('ul').css("display", 'block'); // show sub navs with display:block;
                    $(".jScrollPaneContainer").css("margin-top", "51px");
                    isfoundsubnav = true;

                    if ($(this).attr('rel') == "about") {
                        $('.citibank').css('display', 'block');
                        $('.qantas').css('display', 'block');
                        $('.newslink').css('display', 'block');
                    }
                }
            }
        });

        //select sub nav elements
        if (isfoundsubnav == false) {
            //alert('sub');
            $(".navigation .sub").each(function () {
                //alert($(this).attr('rel'));
                if ($(this).attr('rel') == selctedmenuitem.toLowerCase()) { // selects the subnav and performs below functions
                    $(this).prev().attr('src', 'Content/other/main-nav-line.jpg'); // add line image left of current subnav
                    $(this).parent().parent().prev().css("color", "#666"); // change main nav color to same subnav color
                    $(this).parent().parent().css("display", "block"); // show sub navs with display:block;
                    //$(this).parent().parent().css("", ""); // will select sub nav for styling
                    //$(this).parent().parent().prev().css("", ""); // will select main nav for styling (add .css to style)

                    if (selctedmenuitem.toLowerCase() == "tourism-melbourne-local-attractions") {
                        $("#bg").attr("src", "Content/Background/tourism melbourne2.jpg");
                    }
                    if (selctedmenuitem.toLowerCase() == "tourism-melbourne-enquire") {
                        $("#bg").attr("src", "Content/Background/tourism melbourne2.jpg");
                    }
                    if ($(this).parent().parent().prev().text() == 'about') {
                        $('.qantas').css('display', 'block');
                        $('.citibank').css('display', 'block');
                    }
                }
            });
        }


        $('.hover a').each(function () {

        });

        $('.hover a').hover(function () {
            //$(this).next().css('opacity', '0')
        }, function () {
            //$(this).next('div').css('opacity', '1')
        });
    }
});
