﻿$(document).ready(function () {

    // This is the simplified img hover script
    $('img[hvr]').hover(function () {
        var currentImg = $(this).attr('src');
        $(this).attr('src', $(this).attr('hvr'));
        $(this).attr('hvr', currentImg);
    }, function () {
        var currentImg = $(this).attr('src');
        $(this).attr('src', $(this).attr('hvr'));
        $(this).attr('hvr', currentImg);
    });

    // This adds a watermark to the textbox using the ToolTip attribute for <asp:TextBox or the Title attribute on input.
    $("input[title]").each(function () {
        if ($(this).attr('title') != '') {
            $(this).val($(this).attr('title'));
            $(this).addClass("water");
        }
    }).focus(function () {
        if ($(this).val() == $(this).attr('title')) {
            $(this).val("");
            $(this).removeClass("water");
        }
    }).blur(function () {
        if ($.trim($(this).val()) == "") {
            $(this).val($(this).attr('title'));
            $(this).addClass("water");
        }
    });

    // Autocreate captions for images.
    $("img[longdesc]").each(function () {

        $(this).wrap('<div class="autoImage" />');
        $(this).after('<div class="autoImageCaption">' + $(this).attr('longdesc') + '</div>');
        $(this).parent().attr('style', $(this).attr('style')).attr('class', $(this).attr('class'));
        $(this).removeAttr("style").removeAttr("class");

    });


});

// new stuff from old stuff (resourse js file)

//INITIALIZATION
///////////////////////////
var html = document.getElementsByTagName('html')[0];
jscss('add', html, 'hasScript');
if (detectFlash(6)) jscss('add', html, 'hasFlash');
detectImages();
var hasReqdDOM = (document.getElementsByTagName && document.getElementById);

//alert( document.getElementsByTagName('html')[0].className )
function PageInit() {
    if (!(hasReqdDOM)) return;
    PopUpSafe(document.getElementsByTagName('a'));
    Rollovers(Array('ro_arkansas', 'ro_grouptravel', 'ro_requestinfo', 'ro_facility', 'ro_sitemap', 'ro_home'));
    //initFlash();
    InitNavMenu();
}
addEvent(window, 'load', PageInit);

function initFlash() {
    if (!document.getElementById || typeof (FlashObject) == 'undefined') return;
    myFlash = new FlashObject("/images/mp/sc_flash_final.swf", "flashy", "730", "227", 6.0, "#ffffff");
    myFlash.addParam("wmode", "opaque"); //fix bug with IE 5.x
    myFlash.write("fl_replace");
}


function PopUpSafe(els) {
    if (!els) return;
    for (var i = 0; i < els.length; i++) {
        if (els[i].rel.indexOf("external") >= 0) {
            els[i].onclick = function () { return PopWin(this.href, 'new'); }
        }
        else if (els[i].rel.indexOf(':') >= 0) {
            els[i].onclick = function () { args = this.rel.split(':'); return PopWin(this.href, args[0], args[1], args[2]); }
        }
    }
}

// additional properties for IE compatibility
function IEactive() { jscss('add', this, "IEhover"); jscss('add', this.navMenu, "ddesc"); this.navMenu.onactivate(); }
function IEinactive() { jscss('remove', this, "IEhover"); jscss('remove', this.navMenu, "ddesc"); this.navMenu.ondeactivate(); }


//IMAGE ROLLOVERS
///////////////////////////
var over = new Object();
var out = new Object();
function Rollovers(idArr, func) {
    var imgs, a;
    if (!func) func = getRollSrc;
    if (!document.images) return;

    for (i = 0; i < idArr.length; i++) {
        imgs = getObj(idArr[i]);
        if (!imgs) continue;
        out[idArr[i]] = new Image();
        over[idArr[i]] = new Image();
        out[idArr[i]].src = imgs.src;
        over[idArr[i]].src = func(imgs.src, 1);
        a = imgs.parentNode;
        if ((a && a.tagName.toLowerCase() == 'a')) {
            a.onmouseover = function () { this.childNodes[0].src = over[this.childNodes[0].id].src; }
            a.onmouseout = function () { this.childNodes[0].src = out[this.childNodes[0].id].src; }
            a.onfocus = function () { this.childNodes[0].src = over[this.childNodes[0].id].src; }
            a.onblur = function () { this.childNodes[0].src = out[this.childNodes[0].id].src; }
        }
        else if (imgs.tagName.toLowerCase() == 'input') {
            imgs.onmouseover = function () { this.src = over[this.id].src; }
            imgs.onmouseout = function () { this.src = out[this.id].src; }
        }
    }
}
function InitNavMenu() {
    var mn = document.getElementById('mainnav');
    var oldIE = (document.all && getIEVersion() < 7)
    if (!mn) return;

    var uls = mn.getElementsByTagName('ul');

    var fn_a = function () { this.navMenu.onactivate(); }
    var fn_d = function () { this.navMenu.ondeactivate(); }
    if (oldIE) {
        fn_a = IEactive;
        fn_d = IEinactive;
    }
    for (var i = 0; i < uls.length; i++) {
        //setOpacity(uls[i],0);
        if (uls[i].id == '' || !uls[i].id) uls[i].id = 'menu' + i;
        uls[i].parentNode.navMenu = uls[i];
        uls[i]["onactivate"] = setLyr;
        uls[i]["ondeactivate"] = unsetLyr;
        uls[i].activator = getActivator(uls[i]);
        uls[i].parentNode.onmouseover = fn_a;
        uls[i].parentNode.onmouseout = fn_d;
        if (oldIE) {
            if (uls[i].parentNode.nodeName != 'DD') {
                uls[i].onmouseover = function () { if (this.activator) jscss('add', this.activator, "chsel"); };
                uls[i].onmouseout = function () { if (this.activator) jscss('remove', this.activator, "chsel"); };
            }
        }
    }
}
function getRollSrc(src, hover) { return (hover) ? src.replace(/a.(gif|jpg)/, "b.$1") : src.replace(/b.(gif|jpg)/, "a.$1"); }


//GENERAL PURPOSE FUNCTIONS
///////////////////////////
var wini; //Reference to a window
function PopWin(url, name, width, height) {
    var s;
    if (width || height) {
        h = (height) ? height : 600;
        w = (width) ? width : 800;
        lp = (screen.width) ? (screen.width - w) / 2 : 0;
        tp = (screen.height) ? (screen.height - h) / 2 : 0;
        sc = (name == 'gallery') ? 'no' : 'yes';
        s = 'height=' + h + ',width=' + w + ',top=' + tp + ',left=' + lp + ',scrollbars=' + sc + ',resizable';
    }
    else s = '';
    wini = window.open(url, name, s);
    if (wini) wini.focus();
    return (!wini)
} // PopWin()

function getObj(objId) {
    var obj;
    if (document.getElementById)
        obj = document.getElementById(objId);
    else if (document.all)
        obj = document.all[objId];
    else
        obj = null;
    return obj;
}

function addEvent(obj, evType, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, false);
    }
    else if (obj.attachEvent) {
        var r = obj.attachEvent("on" + evType, fn);
    }
    else {
        if (typeof (obj['on' + evType]) == 'function') {
            var last = obj['on' + evType];
            obj['on' + evType] = null;
            obj['on' + evType] = function () { last(); fn(); };
        }
        else obj['on' + evType] = fn;
    }
}

function findObjPos(obj) {
    var curtop = 0;
    var curleft = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y && obj.x) {
        curtop += obj.y;
        curleft += obj.x;
    }
    var t = new Object();
    t.dx = curleft;
    t.dy = curtop;
    return t;
}


// found at http://www.onlinetools.org/articles/unobtrusivejavascript/cssjsseparation.html
function jscss(a, o, c1, c2) {
    switch (a) {
        case 'swap':
            o.className = !jscss('check', o, c1) ? o.className.replace(c2, c1) : o.className.replace(c1, c2);
            break;
        case 'add':
            if (!jscss('check', o, c1)) { o.className += o.className ? ' ' + c1 : c1; }
            break;
        case 'remove':
            var rep = o.className.match(' ' + c1) ? ' ' + c1 : c1;
            o.className = o.className.replace(rep, '');
            break;
        case 'check':
            return new RegExp('\\b' + c1 + '\\b').test(o.className)
            break;
    }
}


// FUNCTIONS NEEDED FOR VARIOUS DETECTIONS
///////////////////////////////////////////
function getIEVersion() {
    var rv = -1;
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}

function getFlashVersion() {
    var flashversion = 0;
    if (navigator.plugins && navigator.mimeTypes.length) {
        var x = navigator.plugins["Shockwave Flash"];
        if (x && x.description) {
            var y = x.description;
            flashversion = y.charAt(y.indexOf('.') - 1);
        }
    } else {
        result = false;
        for (var i = 15; i >= 3 && result != true; i--) {
            execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.' + i + '"))', 'VBScript');
            flashversion = i;
        }
    }
    return flashversion;
}
function detectFlash(ver) { return (getFlashVersion() >= ver) ? true : false; }

function detectImages() {
    if (!document.getElementById) return;
    jscss('add', html, 'noImages');
    var detImg = new Image();
    var tmp = new Date();
    var suffix = tmp.getTime();
    detImg.src = '/images/blank.gif?' + suffix;
    detImg.onload = function () { jscss('remove', html, 'noImages'); }

}
