﻿/// <reference path="jquery.js" />

function isKeyPressed(e, key) {
    // handle i.e. (window.event) and firefox (e)
    var eventInstance = window.event ? event : e;

    // handle i.e. (charCode) and firefox (keyCode)
    var unicode = eventInstance.charCode ? eventInstance.charCode : eventInstance.keyCode;
    return (unicode == key ? true : false);
}

$(document).ready(function() {

    alternateRows();
    thickBox();

    $(".FleetlistRowHeader").click(function() {
        if ($(this).next("div").find(".vesselTable").length == 0) {
            pageId = $(this).next("div").find(".noPrint").next("div").attr("id");
            $(this).next("div").find(".tableContainer").load("/Customer/Pages/VesselTablePage.aspx?lang=" + lang + "&pageId=" + pageId, null, function() {
                $(".explanation").attr("src", "http://www.brostrom.com/customer/images/vessel/explanation.gif");
                }
            );
        }
    });

    $("#movielist").change(function() {
        if ($(".currentmovie iframe").length > 0) {
            var url = $(".currentmovie iframe").attr("src");
            if (url.indexOf("&tstamp=") > -1) {
                url = url.replace(/&tstamp=(\d)+/, "&tstamp=" + new Date().getTime());
            } else {
                url += "&tstamp=" + new Date().getTime();
            }
            $(".currentmovie iframe").attr("src", url);
        }
        $(".streamiocontainer > p").removeClass("currentmovie").addClass("none");
        $(".streamiocontainer > p:nth(" + $("#movielist").val() + ")").removeClass("none").addClass("currentmovie");
    });

    $("#movielist").change();
});


function alternateRows() {
    /*
    Standards Compliant Script
    Alternates Table Columns
    Author : Kevin Cannon
    http://www.multiblah.com
    Last Edited: 12.12.2004
    Version 1.0
	
Search through the document for tables with the "alternateRows" class,
    and set the class of even rows to "even" to appropriate rows <tr>
	
Changes:
    4/10/2004 - Added in AddLoadEvent function which piggybacks code onto window.onLoad 
    */

    // Main function, called when the page loads
    var i, j;
    if (!document.getElementById) return

    // Alternate rows on tables
    var tables = document.getElementsByTagName("table");
    //search through tables in document
    for (i = 0; i < tables.length; i++) {
        // If table has the right classname
        if (tables[i].className.indexOf("alternateRows") != -1) {
            if (tables[i].getElementsByTagName("tbody").length > 0) {
                rows = tables[i].getElementsByTagName("tbody")[0].getElementsByTagName("tr");
            } else {
                rows = tables[i].getElementsByTagName("tr");
            }
            applyClasstoRows(rows);
        }
    }
}

// Function, which is passed a table reference, applies the class 'even' to each even row, <tr> tag
function applyClasstoRows(myRows) {
    // search through rows
    for (j = 0; j < rows.length; j++) {
        if (j == 0) {
            rows[j].setAttribute("className", "first");
            rows[j].setAttribute("class", "first");
            j++;
        }
        // Set class for even rows (odd doesn't need to be set)
        if (j % 2 == 0) {
            rows[j].setAttribute("className", "even");
            rows[j].setAttribute("class", "even");
        }
        else {
            rows[j].setAttribute("className", "odd");
            rows[j].setAttribute("class", "odd");
        }
            
    }
}


function thickBox() {
    // Add thickbox function to linked images with class lightBox
    var links = $("a img.lightBox").parent();
    for (link = 0; link < links.length; link++) {
        links[link].setAttribute("className", "thickbox");
        links[link].setAttribute("class", "thickbox");
    }
}