/*
* jquery.tools 1.1.2 - The missing UI library for the Web
* 
* [tools.scrollable-1.1.2, tools.scrollable.circular-0.5.1, tools.scrollable.autoscroll-1.0.1, tools.scrollable.navigator-1.0.2]
* 
* Copyright (c) 2009 Tero Piirainen
* http://flowplayer.org/tools/
*
* Dual licensed under MIT and GPL 2+ licenses
* http://www.opensource.org/licenses
* 
* -----
* 
* File generated: Wed Apr 14 10:16:18 GMT 2010
*/
(function(b) { b.tools = b.tools || {}; b.tools.scrollable = { version: "1.1.2", conf: { size: 5, vertical: false, speed: 400, keyboard: true, keyboardSteps: null, disabledClass: "disabled", hoverClass: null, clickable: true, activeClass: "active", easing: "swing", loop: false, items: ".items", item: null, prev: ".prev", next: ".next", prevPage: ".prevPage", nextPage: ".nextPage", api: false} }; var c; function a(o, m) { var r = this, p = b(this), d = !m.vertical, e = o.children(), k = 0, i; if (!c) { c = r } b.each(m, function(s, t) { if (b.isFunction(t)) { p.bind(s, t) } }); if (e.length > 1) { e = b(m.items, o) } function l(t) { var s = b(t); return m.globalNav ? s : o.parent().find(t) } o.data("finder", l); var f = l(m.prev), h = l(m.next), g = l(m.prevPage), n = l(m.nextPage); b.extend(r, { getIndex: function() { return k }, getClickIndex: function() { var s = r.getItems(); return s.index(s.filter("." + m.activeClass)) }, getConf: function() { return m }, getSize: function() { return r.getItems().size() }, getPageAmount: function() { return Math.ceil(this.getSize() / m.size) }, getPageIndex: function() { return Math.ceil(k / m.size) }, getNaviButtons: function() { return f.add(h).add(g).add(n) }, getRoot: function() { return o }, getItemWrap: function() { return e }, getItems: function() { return e.children(m.item) }, getVisibleItems: function() { return r.getItems().slice(k, k + m.size) }, seekTo: function(s, w, t) { if (s < 0) { s = 0 } if (k === s) { return r } if (b.isFunction(w)) { t = w } if (s > r.getSize() - m.size) { return m.loop ? r.begin() : this.end() } var u = r.getItems().eq(s); if (!u.length) { return r } var v = b.Event("onBeforeSeek"); p.trigger(v, [s]); if (v.isDefaultPrevented()) { return r } if (w === undefined || b.isFunction(w)) { w = m.speed } function x() { if (t) { t.call(r, s) } p.trigger("onSeek", [s]) } if (d) { e.animate({ left: -u.position().left }, w, m.easing, x) } else { e.animate({ top: -u.position().top }, w, m.easing, x) } c = r; k = s; v = b.Event("onStart"); p.trigger(v, [s]); if (v.isDefaultPrevented()) { return r } f.add(g).toggleClass(m.disabledClass, s === 0); h.add(n).toggleClass(m.disabledClass, s >= r.getSize() - m.size); return r }, move: function(u, t, s) { i = u > 0; return this.seekTo(k + u, t, s) }, next: function(t, s) { return this.move(1, t, s) }, prev: function(t, s) { return this.move(-1, t, s) }, movePage: function(w, v, u) { i = w > 0; var s = m.size * w; var t = k % m.size; if (t > 0) { s += (w > 0 ? -t : m.size - t) } return this.move(s, v, u) }, prevPage: function(t, s) { return this.movePage(-1, t, s) }, nextPage: function(t, s) { return this.movePage(1, t, s) }, setPage: function(t, u, s) { return this.seekTo(t * m.size, u, s) }, begin: function(t, s) { i = false; return this.seekTo(0, t, s) }, end: function(t, s) { i = true; var u = this.getSize() - m.size; return u > 0 ? this.seekTo(u, t, s) : r }, reload: function() { p.trigger("onReload"); return r }, focus: function() { c = r; return r }, click: function(u) { var v = r.getItems().eq(u), s = m.activeClass, t = m.size; if (u < 0 || u >= r.getSize()) { return r } if (t == 1) { if (m.loop) { return r.next() } if (u === 0 || u == r.getSize() - 1) { i = (i === undefined) ? true : !i } return i === false ? r.prev() : r.next() } if (t == 2) { if (u == k) { u-- } r.getItems().removeClass(s); v.addClass(s); return r.seekTo(u, time, fn) } if (!v.hasClass(s)) { r.getItems().removeClass(s); v.addClass(s); var x = Math.floor(t / 2); var w = u - x; if (w > r.getSize() - t) { w = r.getSize() - t } if (w !== u) { return r.seekTo(w) } } return r }, bind: function(s, t) { p.bind(s, t); return r }, unbind: function(s) { p.unbind(s); return r } }); b.each("onBeforeSeek,onStart,onSeek,onReload".split(","), function(s, t) { r[t] = function(u) { return r.bind(t, u) } }); f.addClass(m.disabledClass).click(function() { r.prev() }); h.click(function() { r.next() }); n.click(function() { r.nextPage() }); if (r.getSize() < m.size) { h.add(n).addClass(m.disabledClass) } g.addClass(m.disabledClass).click(function() { r.prevPage() }); var j = m.hoverClass, q = "keydown." + Math.random().toString().substring(10); r.onReload(function() { if (j) { r.getItems().hover(function() { b(this).addClass(j) }, function() { b(this).removeClass(j) }) } if (m.clickable) { r.getItems().each(function(s) { b(this).unbind("click.scrollable").bind("click.scrollable", function(t) { if (b(t.target).is("a")) { return } return r.click(s) }) }) } if (m.keyboard) { b(document).unbind(q).bind(q, function(t) { if (t.altKey || t.ctrlKey) { return } if (m.keyboard != "static" && c != r) { return } var u = m.keyboardSteps; if (d && (t.keyCode == 37 || t.keyCode == 39)) { r.move(t.keyCode == 37 ? -u : u); return t.preventDefault() } if (!d && (t.keyCode == 38 || t.keyCode == 40)) { r.move(t.keyCode == 38 ? -u : u); return t.preventDefault() } return true }) } else { b(document).unbind(q) } }); r.reload() } b.fn.scrollable = function(d) { var e = this.eq(typeof d == "number" ? d : 0).data("scrollable"); if (e) { return e } var f = b.extend({}, b.tools.scrollable.conf); d = b.extend(f, d); d.keyboardSteps = d.keyboardSteps || d.size; this.each(function() { e = new a(b(this), d); b(this).data("scrollable", e) }); return d.api ? e : this } })(jQuery);
(function(b) { var a = b.tools.scrollable; a.plugins = a.plugins || {}; a.plugins.circular = { version: "0.5.1", conf: { api: false, clonedClass: "cloned"} }; b.fn.circular = function(e) { var d = b.extend({}, a.plugins.circular.conf), c; b.extend(d, e); this.each(function() { var i = b(this).scrollable(), n = i.getItems(), k = i.getConf(), f = i.getItemWrap(), j = 0; if (i) { c = i } if (n.length < k.size) { return false } n.slice(0, k.size).each(function(o) { b(this).clone().appendTo(f).click(function() { i.click(n.length + o) }).addClass(d.clonedClass) }); var l = b.makeArray(n.slice(-k.size)).reverse(); b(l).each(function(o) { b(this).clone().prependTo(f).click(function() { i.click(-o - 1) }).addClass(d.clonedClass) }); var m = f.children(k.item); var h = k.hoverClass; if (h) { m.hover(function() { b(this).addClass(h) }, function() { b(this).removeClass(h) }) } function g(o) { var p = m.eq(o); if (k.vertical) { f.css({ top: -p.position().top }) } else { f.css({ left: -p.position().left }) } } g(k.size); b.extend(i, { move: function(s, r, p, q) { var u = j + s + k.size; var t = u > i.getSize() - k.size; if (u <= 0 || t) { var o = j + k.size + (t ? -n.length : n.length); g(o); u = o + s } if (q) { m.removeClass(k.activeClass).eq(u + Math.floor(k.size / 2)).addClass(k.activeClass) } if (u === j + k.size) { return self } return i.seekTo(u, r, p) }, begin: function(p, o) { return this.seekTo(k.size, p, o) }, end: function(p, o) { return this.seekTo(n.length, p, o) }, click: function(p, r, q) { if (!k.clickable) { return self } if (k.size == 1) { return this.next() } var s = p - j, o = k.activeClass; s -= Math.floor(k.size / 2); return this.move(s, r, q, true) }, getIndex: function() { return j }, setPage: function(p, q, o) { return this.seekTo(p * k.size + k.size, q, o) }, getPageAmount: function() { return Math.ceil(n.length / k.size) }, getPageIndex: function() { if (j < 0) { return this.getPageAmount() - 1 } if (j >= n.length) { return 0 } var o = (j + k.size) / k.size - 1; return o }, getVisibleItems: function() { var o = j + k.size; return m.slice(o, o + k.size) } }); i.onStart(function(p, o) { j = o - k.size; return false }); i.getNaviButtons().removeClass(k.disabledClass) }); return d.api ? c : this } })(jQuery);
(function(b) { var a = b.tools.scrollable; a.plugins = a.plugins || {}; a.plugins.autoscroll = { version: "1.0.1", conf: { autoplay: true, interval: 3000, autopause: true, steps: 1, api: false} }; b.fn.autoscroll = function(d) { if (typeof d == "number") { d = { interval: d} } var e = b.extend({}, a.plugins.autoscroll.conf), c; b.extend(e, d); this.each(function() { var g = b(this).scrollable(); if (g) { c = g } var i, f, h = true; g.play = function() { if (i) { return } h = false; i = setInterval(function() { g.move(e.steps) }, e.interval); g.move(e.steps) }; g.pause = function() { i = clearInterval(i) }; g.stop = function() { g.pause(); h = true }; if (e.autopause) { g.getRoot().add(g.getNaviButtons()).hover(function() { g.pause(); clearInterval(f) }, function() { if (!h) { f = setTimeout(g.play, e.interval) } }) } if (e.autoplay) { setTimeout(g.play, e.interval) } }); return e.api ? c : this } })(jQuery);
(function(b) { var a = b.tools.scrollable; a.plugins = a.plugins || {}; a.plugins.navigator = { version: "1.0.2", conf: { navi: ".navi", naviItem: null, activeClass: "active", indexed: false, api: false, idPrefix: null} }; b.fn.navigator = function(d) { var e = b.extend({}, a.plugins.navigator.conf), c; if (typeof d == "string") { d = { navi: d} } d = b.extend(e, d); this.each(function() { var i = b(this).scrollable(), f = i.getRoot(), l = f.data("finder").call(null, d.navi), g = null, k = i.getNaviButtons(); if (i) { c = i } i.getNaviButtons = function() { return k.add(l) }; function j() { if (!l.children().length || l.data("navi") == i) { l.empty(); l.data("navi", i); for (var m = 0; m < i.getPageAmount(); m++) { l.append(b("<" + (d.naviItem || "a") + "/>")) } g = l.children().each(function(n) { var o = b(this); o.click(function(p) { i.setPage(n); return p.preventDefault() }); if (d.indexed) { o.text(n) } if (d.idPrefix) { o.attr("id", d.idPrefix + n) } }) } else { g = d.naviItem ? l.find(d.naviItem) : l.children(); g.each(function(n) { var o = b(this); o.click(function(p) { i.setPage(n); return p.preventDefault() }) }) } g.eq(0).addClass(d.activeClass) } i.onStart(function(o, n) { var m = d.activeClass; g.removeClass(m).eq(i.getPageIndex()).addClass(m) }); i.onReload(function() { j() }); j(); var h = g.filter("[href=" + location.hash + "]"); if (h.length) { i.move(g.index(h)) } }); return d.api ? c : this } })(jQuery);
/*tools.tabs 1.0.4*/
(function(d) { d.tools = d.tools || {}; d.tools.tabs = { version: "1.0.4", conf: { tabs: "a", current: "current", onBeforeClick: null, onClick: null, effect: "default", initialIndex: 0, event: "click", api: false, rotate: false }, addEffect: function(e, f) { c[e] = f } }; var c = { "default": function(f, e) { this.getPanes().hide().eq(f).show(); e.call() }, fade: function(g, e) { var f = this.getConf(), j = f.fadeOutSpeed, h = this.getPanes(); if (j) { h.fadeOut(j) } else { h.hide() } h.eq(g).fadeIn(f.fadeInSpeed, e) }, slide: function(f, e) { this.getPanes().slideUp(200); this.getPanes().eq(f).slideDown(400, e) }, ajax: function(f, e) { this.getPanes().eq(0).load(this.getTabs().eq(f).attr("href"), e) } }; var b; d.tools.tabs.addEffect("horizontal", function(f, e) { if (!b) { b = this.getPanes().eq(0).width() } this.getCurrentPane().animate({ width: 0 }, function() { d(this).hide() }); this.getPanes().eq(f).animate({ width: b }, function() { d(this).show(); e.call() }) }); function a(g, h, f) { var e = this, j = d(this), i; d.each(f, function(k, l) { if (d.isFunction(l)) { j.bind(k, l) } }); d.extend(this, { click: function(k, n) { var o = e.getCurrentPane(); var l = g.eq(k); if (typeof k == "string" && k.replace("#", "")) { l = g.filter("[href*=" + k.replace("#", "") + "]"); k = Math.max(g.index(l), 0) } if (f.rotate) { var m = g.length - 1; if (k < 0) { return e.click(m, n) } if (k > m) { return e.click(0, n) } } if (!l.length) { if (i >= 0) { return e } k = f.initialIndex; l = g.eq(k) } if (k === i) { return e } n = n || d.Event(); n.type = "onBeforeClick"; j.trigger(n, [k]); if (n.isDefaultPrevented()) { return } c[f.effect].call(e, k, function() { n.type = "onClick"; j.trigger(n, [k]) }); n.type = "onStart"; j.trigger(n, [k]); if (n.isDefaultPrevented()) { return } i = k; g.removeClass(f.current); l.addClass(f.current); return e }, getConf: function() { return f }, getTabs: function() { return g }, getPanes: function() { return h }, getCurrentPane: function() { return h.eq(i) }, getCurrentTab: function() { return g.eq(i) }, getIndex: function() { return i }, next: function() { return e.click(i + 1) }, prev: function() { return e.click(i - 1) }, bind: function(k, l) { j.bind(k, l); return e }, onBeforeClick: function(k) { return this.bind("onBeforeClick", k) }, onClick: function(k) { return this.bind("onClick", k) }, unbind: function(k) { j.unbind(k); return e } }); g.each(function(k) { d(this).bind(f.event, function(l) { e.click(k, l); return false }) }); if (location.hash) { e.click(location.hash) } else { if (f.initialIndex === 0 || f.initialIndex > 0) { e.click(f.initialIndex) } } h.find("a[href^=#]").click(function(k) { e.click(d(this).attr("href"), k) }) } d.fn.tabs = function(i, f) { var g = this.eq(typeof f == "number" ? f : 0).data("tabs"); if (g) { return g } if (d.isFunction(f)) { f = { onBeforeClick: f} } var h = d.extend({}, d.tools.tabs.conf), e = this.length; f = d.extend(h, f); this.each(function(l) { var j = d(this); var k = j.find(f.tabs); if (!k.length) { k = j.children() } var m = i.jquery ? i : j.children(i); if (!m.length) { m = e == 1 ? d(i) : j.parent().find(i) } g = new a(k, m, f); j.data("tabs", g) }); return f.api ? g : this } })(jQuery);

/*x an y position*/
$.fn.x = function(n) { var result = null; this.each(function() { var o = this; if (n === undefined) { var x = 0; if (o.offsetParent) { while (o.offsetParent) { x += o.offsetLeft; o = o.offsetParent } } if (result === null) { result = x } else { result = Math.min(result, x) } } else { o.style.left = n + 'px' } }); return result };
$.fn.y = function(n) { var result = null; this.each(function() { var o = this; if (n === undefined) { var y = 0; if (o.offsetParent) { while (o.offsetParent) { y += o.offsetTop; o = o.offsetParent } } if (result === null) { result = y } else { result = Math.min(result, y) } } else { o.style.top = n + 'px' } }); return result };

/*everytime*/
jQuery.fn.extend({ everyTime: function(interval, label, fn, times, belay) { return this.each(function() { jQuery.timer.add(this, interval, label, fn, times, belay); }); }, oneTime: function(interval, label, fn) { return this.each(function() { jQuery.timer.add(this, interval, label, fn, 1); }); }, stopTime: function(label, fn) { return this.each(function() { jQuery.timer.remove(this, label, fn); }); } }); jQuery.extend({ timer: { guid: 1, global: {}, regex: /^([0-9]+)\s*(.*s)?$/, powers: { 'ms': 1, 'cs': 10, 'ds': 100, 's': 1000, 'das': 10000, 'hs': 100000, 'ks': 1000000 }, timeParse: function(value) { if (value == undefined || value == null) return null; var result = this.regex.exec(jQuery.trim(value.toString())); if (result[2]) { var num = parseInt(result[1], 10); var mult = this.powers[result[2]] || 1; return num * mult; } else { return value; } }, add: function(element, interval, label, fn, times, belay) { var counter = 0; if (jQuery.isFunction(label)) { if (!times) times = fn; fn = label; label = interval; } interval = jQuery.timer.timeParse(interval); if (typeof interval != 'number' || isNaN(interval) || interval <= 0) return; if (times && times.constructor != Number) { belay = !!times; times = 0; } times = times || 0; belay = belay || false; if (!element.$timers) element.$timers = {}; if (!element.$timers[label]) element.$timers[label] = {}; fn.$timerID = fn.$timerID || this.guid++; var handler = function() { if (belay && this.inProgress) return; this.inProgress = true; if ((++counter > times && times !== 0) || fn.call(element, counter) === false) jQuery.timer.remove(element, label, fn); this.inProgress = false; }; handler.$timerID = fn.$timerID; if (!element.$timers[label][fn.$timerID]) element.$timers[label][fn.$timerID] = window.setInterval(handler, interval); if (!this.global[label]) this.global[label] = []; this.global[label].push(element); }, remove: function(element, label, fn) { var timers = element.$timers, ret; if (timers) { if (!label) { for (label in timers) this.remove(element, label, fn); } else if (timers[label]) { if (fn) { if (fn.$timerID) { window.clearInterval(timers[label][fn.$timerID]); delete timers[label][fn.$timerID]; } } else { for (var fn in timers[label]) { window.clearInterval(timers[label][fn]); delete timers[label][fn]; } } for (ret in timers[label]) break; if (!ret) { ret = null; delete timers[label]; } } for (ret in timers) break; if (!ret) element.$timers = null; } } } }); if (jQuery.browser.msie) jQuery(window).one("unload", function() { var global = jQuery.timer.global; for (var label in global) { var els = global[label], i = els.length; while (--i) jQuery.timer.remove(els[i], label); } });

/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($) { $.fn.hoverIntent = function(f, g) { var cfg = { sensitivity: 7, interval: 100, timeout: 0 }; cfg = $.extend(cfg, g ? { over: f, out: g} : f); var cX, cY, pX, pY; var track = function(ev) { cX = ev.pageX; cY = ev.pageY; }; var compare = function(ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); if ((Math.abs(pX - cX) + Math.abs(pY - cY)) < cfg.sensitivity) { $(ob).unbind("mousemove", track); ob.hoverIntent_s = 1; return cfg.over.apply(ob, [ev]); } else { pX = cX; pY = cY; ob.hoverIntent_t = setTimeout(function() { compare(ev, ob); }, cfg.interval); } }; var delay = function(ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); ob.hoverIntent_s = 0; return cfg.out.apply(ob, [ev]); }; var handleHover = function(e) { var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget; while (p && p != this) { try { p = p.parentNode; } catch (e) { p = this; } } if (p == this) { return false; } var ev = jQuery.extend({}, e); var ob = this; if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); } if (e.type == "mouseover") { pX = ev.pageX; pY = ev.pageY; $(ob).bind("mousemove", track); if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout(function() { compare(ev, ob); }, cfg.interval); } } else { $(ob).unbind("mousemove", track); if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout(function() { delay(ev, ob); }, cfg.timeout); } } }; return this.mouseover(handleHover).mouseout(handleHover); }; })(jQuery);

/******************************************************************/
/* Replace static google map with dynamic map through client side */
/******************************************************************/
$(document).ready(function() {

    var hackIE6 = false;
    if ($.browser.msie && ($.browser.version == "6.0")) { hackIE6 = true; }

    //featuredColumns on the homepage - equal height
    //var longest = 0;

    var longest = 0,
    $featuredRTE = $('.featuredColumns .componentRTE'),
    totImages = $featuredRTE.find('img').length,
    counterImages = 0;
    allLoaded = false,
    t = null;

    //console.log('totImages ' + totImages);
    if (totImages == 0) { allLoaded = true; }

    $featuredRTE.find('img').each(function(i) {
        //console.log(i + ' ' + $(this).attr('src'));
        $('<img />').load(function() {
            counterImages = counterImages + 1;

            if (counterImages >= totImages) {
                //console.log('all loaded ' + counterImages + '-->' + totImages);
                allLoaded = true;
            }
        }).attr('src', $(this).attr('src'));
    });
    calculateEqualHeight();

    function calculateEqualHeight() {
        if (allLoaded) {
            clearTimeout(t);
            //console.log('can do equal height');
            $featuredRTE.each(function(i) {
                $(this).removeAttr('style');
                if ($(this).height() > longest) { longest = $(this).height(); }
                //console.log(i + ' ' + $(this).height() + ' longest: ' + longest);
            });
            if (longest < 270) { longest = 270; }
            $('.featuredColumns .componentRTE').attr('style', 'height:' + longest + 'px; border-bottom-width:4px;');
        }
        else {
            t = setTimeout(function() {
                calculateEqualHeight();
            }, 500);
            //console.log('wait 500ms');
        }
    }
    /*
    $featuredRTE.each(function(i) {
    $(this).removeAttr('style');
    if ($(this).height() > longest) { longest = $(this).height(); }
    console.log(i + ' ' + $(this).height() + ' longest: ' + longest);
    });
    */
    //$('.featuredColumns .componentRTE').css({ "height": longest + "px !important", "border-bottom-width": "4px" });
    //$('.featuredColumns .componentRTE').attr('style', 'height:' + longest + 'px !important; border-bottom-width:4px;');

    //selectLanguage Dropdown    
    $('#selectLanguage select').selectbox({ selectLanguage: true });
    $('#selectLanguage').fadeIn(1000);

    //add delay to mega menu opening
    $('#defaultNav li.parent').hoverIntent({
        sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
        interval: 500, // number = milliseconds for onMouseOver polling interval
        over: function() {// function = onMouseOver callback (REQUIRED)
            var hoverClass = "hover";

            if (hackIE6) {
                if ($(this).hasClass('liDestCom')) { hoverClass = 'liDestComHover'; }
                else if ($(this).hasClass('liBusOp')) { hoverClass = 'liBusOpHover'; }
                else if ($(this).hasClass('liParksCul')) { hoverClass = 'liParksCulHover'; }
                else if ($(this).hasClass('liOnlineCom')) { hoverClass = 'liOnlineComHover'; }
                else if ($(this).hasClass('liHome')) { hoverClass = 'liHomeHover'; }
            }
            $(this).addClass(hoverClass).find(".subNavHolder").animate({ "height": "toggle" }, 350);
        },
        timeout: 500, // number = milliseconds delay before onMouseOut    
        out: function() {// function = onMouseOut callback (REQUIRED)
            var hoverClass = "hover";
            if (hackIE6) {
                if ($(this).hasClass('liDestCom')) { hoverClass = 'liDestComHover'; }
                else if ($(this).hasClass('liBusOp')) { hoverClass = 'liBusOpHover'; }
                else if ($(this).hasClass('liParksCul')) { hoverClass = 'liParksCulHover'; }
                else if ($(this).hasClass('liOnlineCom')) { hoverClass = 'liOnlineComHover'; }
                else if ($(this).hasClass('liHome')) { hoverClass = 'liHomeHover'; }
            }
            $(this).removeClass(hoverClass).find(".subNavHolder").animate({ "height": "toggle" }, 300);
        }
    });

    //search area
    $("#searchTab li a").each(function(i) {
        var fieldsetClass = "fieldsetHolder itemTop clearer";
        if (i == 0) { fieldsetClass = "fieldsetHolder itemRight clearer"; }
        var thisParent = $(this).parent('li');
        $(this).click(function() {
            $('#searchTab li').removeClass('selected').removeClass('prevSelected');
            $(thisParent).addClass('selected').prev().addClass('prevSelected');
            $('#fieldsetHolder').attr('class', fieldsetClass);
            $('#searchArea input.hfType').val(thisParent.classJson().type);
        });
    });
    $('#searchArea .lnkSearch').click(function() {
        var lnkToggle = $('#searchArea .lnkToggle');
        $(lnkToggle).hide();

        var slideTo = "150px";
        if ($("#siteFunction").hasClass('siteFunctionAdvanced')) {
            slideTo = "297px";
        }

        $('#searchArea').animate({ height: "0px" }, 500, function() {
            $(this).removeClass('searchAreaCollapsed');
            $('#siteFunction').removeClass('siteFunctionCollapsed');
        });
        $('#searchArea').animate({ height: slideTo }, 500, function() {
            $(lnkToggle).removeClass('expand')
                        .addClass('collapse')
                        .html('collapse')
                        .attr('title', 'collapse').show();
        });
        $('#siteFunction').animate({ height: slideTo }, 500, function() { });
    });


    $('#searchArea .lnkToggle').click(
        function() {
            var lnkToggle = $(this);
            $(lnkToggle).hide();

            var slideTo = "150px";
            if ($("#siteFunction").hasClass('siteFunctionAdvanced')) {
                slideTo = "297px";
            }
            if ($(lnkToggle).hasClass('collapse')) {
                $('#searchArea').animate({ height: "0px" }, 500, function() {
                    $(this).addClass('searchAreaCollapsed');
                    $('#siteFunction').addClass('siteFunctionCollapsed');
                });
                $('#searchArea').animate({ height: "67px" }, 500, function() {
                    $(lnkToggle).removeClass('collapse')
                        .addClass('expand')
                        .html('expand')
                        .attr('title', 'expand').show();
                });
                $('#siteFunction').animate({ height: "67px" }, 500, function() { });
            }
            else {
                $('#searchArea').animate({ height: "0px" }, 500, function() {
                    $(this).removeClass('searchAreaCollapsed');
                    $('#siteFunction').removeClass('siteFunctionCollapsed');

                    $('#searchArea').animate({ height: slideTo }, 500, function() {
                        $(lnkToggle).removeClass('expand')
                        .addClass('collapse')
                        .html('collapse')
                        .attr('title', 'collapse').show();
                    });
                    $('#siteFunction').animate({ height: slideTo }, 500, function() { });
                });

            }
        }
    );

    $('#lnkBasicAdvanced').click(
        function() {
            $('#searchArea .lnkToggle').hide();
            if ($(this).hasClass('basic')) {

                $('.pnlSearch').slideUp(500, function() {
                    $('#lnkBasicAdvanced')
                        .html('Basic Search')
                        .attr('title', 'Basic Search')
                        .removeClass('basic');
                });
                $("#siteFunction").animate({ height: "297px" }, 500, function() {
                    $('.pnlAdvSearch').slideDown(500);
                }).addClass('siteFunctionAdvanced');
                $('#searchArea').animate({ height: "297px" }, 500, function() {
                    $('#searchArea .lnkToggle').show();
                });
            }
            else {
                $('#searchArea').animate({ height: "150px" }, 500, function() { });
                $("#siteFunction").animate({ height: "150px" }, 500, function() {
                    $(this).removeClass('siteFunctionAdvanced');
                    $('.pnlSearch').slideDown();
                });
                $('.pnlAdvSearch').slideUp(500, function() {
                    $('#lnkBasicAdvanced')
                        .html('Advanced Search')
                        .attr('title', 'Advanced Search')
                        .addClass('basic');
                    $('#searchArea .lnkToggle').show();
                });
            }

        }
    );

    //social sharing image hover
    $(".socialSharing a img").hover(
        function() {
            var this_src = $(this).attr("src");
            if (this_src.indexOf("_hover.png") == -1) {
                $(this).attr("src", this_src.replace(/.png/, "_hover.png"));
            }
        },
        function() {
            var this_src = $(this).attr("src");
            $(this).attr("src", this_src.replace(/_hover.png/, ".png"));
        }
    );

    //FAQ    
    var $FAQcomponent = $("#FAQcomponent");
    if ($FAQcomponent.length > 0) {
        $("dt", $FAQcomponent).toggle(
            function() { $(this).addClass('selected'); $(this).next("dd").addClass("show"); },
            function() { $(this).removeClass('selected'); $(this).next("dd").removeClass("show"); });
    }

    //watermarks
    var swapValues = [];
    $(".watermarks").each(function(i) {
        swapValues[i] = $(this).val();
        $(this).focus(function() {
            if ($(this).hasClass("enterkey")) {
                if ($(this).val() == "Enter Keywords") {
                    $(this).val("");
                }
            }
            else if ($(this).hasClass("findall")) {
                if ($(this).val() == "Find all these words...") {
                    $(this).val("");
                }
            }
            else if ($(this).hasClass("findexact")) {
                if ($(this).val() == "Find exact wording/phrase...") {
                    $(this).val("");
                }
            }
            else {
                if ($(this).val() == swapValues[i]) {
                    $(this).val("")
                }
            }
        }).blur(function() {
            if ($(this).hasClass("enterkey")) {
                if ($.trim($(this).val()) == "") {
                    $(this).val("Enter Keywords");
                }
            }
            else if ($(this).hasClass("findall")) {
                if ($.trim($(this).val()) == "") {
                    $(this).val("Find all these words...");
                }
            }
            else if ($(this).hasClass("findexact")) {
                if ($.trim($(this).val()) == "") {
                    $(this).val("Find exact wording/phrase...");
                }
            }
            else {
                if ($.trim($(this).val()) == "") {
                    $(this).val(swapValues[i])
                }
            }
        })
    })

    //    $(".watermarksSearch").each(function(i) {
    //        $(this).focus(function() {
    //            if ($(this).val() == "Enter Keywords") {
    //                $(this).val("");
    //            }
    //        }).blur(function() {
    //            if ($.trim($(this).val()) == "") {
    //                $(this).val("Enter Keywords");
    //            }
    //        })
    //    });
    //    

    if ($('#pageMode') && $('#pageMode').val() == 'edit') return;
    if ($('#pageMode') && $('#pageMode').val() == 'preview') return;

    var staticMaps = $('.gmap');

    var parseQueryString = function(src) {
        var qs = new Hashtable();
        $.each(src.split('&'), function(i) {
            var kv = this;
            if (kv == "") return;
            var key = kv.split('=')[0];
            var value = kv.split('=')[1];
            qs.put(key, value);
        });
        return qs;
    };

    $.each(staticMaps, function(i) {
        var staticMap = this;

        //grab all meta
        var src = $(staticMap).attr('src').replace(/^.*\?/, '');
        var queryString = parseQueryString(src);
        var lat = queryString.get('center').split(',')[0];
        var lng = queryString.get('center').split(',')[1];
        var width = queryString.get('size').split('x')[0];
        var height = queryString.get('size').split('x')[1];
        var zoom = Number(queryString.get('zoom'));
        var maptype = queryString.get('maptype');
        var markers = queryString.get('markers');


        //insert placeholder
        var dynamicMap = $('<div/>').attr('id', 'dynamic_gmap_' + i)
            .css('display', 'inline-block')
            .css('width', width + 'px')
            .css('height', height + 'px')
            .css('overflow', 'hidden');
        $(staticMap).after(dynamicMap);
        $(staticMap).hide();

        //create gmap object
        var tmpGMap = new GMap2(dynamicMap[0]);
        tmpGMap.setCenter(new GLatLng(lat, lng), zoom);
        tmpGMap.setUIToDefault();

        if (maptype == 'roadmap') tmpGMap.setMapType(G_NORMAL_MAP);
        else if (maptype == 'satellite') tmpGMap.setMapType(G_SATELLITE_MAP);
        else if (maptype == 'hybrid') tmpGMap.setMapType(G_HYBRID_MAP);
        else if (maptype == 'terrain') tmpGMap.setMapType(G_PHYSICAL_MAP);

        markers = markers.replace(/%7C/g, '|');

        $.each(markers.split('|'), function(i) {
            if (this == "") return;
            var mlat = this.split(',')[0];
            var mlng = this.split(',')[1];
            tmpGMap.addOverlay(new GMarker(new GLatLng(mlat, mlng)));
        });

    });
});

/******************************************************************/
/* Client side code for email subscription component              */
/******************************************************************/
var EmailSC_frontEnd = {
    subscribe: function(cid, dbId) {
        var t = this;
        var fieldArray = []; //we will fill this and send to web service
        var valid = true;

        // text fields
        var textFields = $('.componentES_' + cid + ' .fields input.text');
        $.each(textFields, function(i) {
            var field = this;
            var type = field.type.toLowerCase(); var name = field.name; var value = field.value; var checked = field.checked;

            if ($(field).hasClass('mandatory') && $.trim(value).length <= 0) { valid = false; return false; } //validation
            fieldArray.push({ Name: name, Value: value });

        });

        // radio fields
        var radioWraps = $('.componentES_' + cid + ' .fields .radio_wrap');
        $.each(radioWraps, function(i) {
            var name = $(this).attr('title');
            var mandatory = $(this).hasClass('mandatory');
            var $radios = $('.radio:checked', $(this));
            if (mandatory && $radios.length <= 0) { valid = false; return false; } //validation
            var value = $radios.val();
            fieldArray.push({ Name: name, Value: value });
        });


        // select fields
        var selectFields = $('.componentES_' + cid + ' .fields select.field');
        $.each(selectFields, function(i) {
            var field = this;
            var name = field.name;
            var options = $('option', $(field));
            var value = null;

            $.each(options, function(j) {
                var option = this;
                if (option.selected && $(field).hasClass('mandatory') && $(option).hasClass('default')) { //validation
                    valid = false;
                    return false;
                }
                if (option.selected) {
                    value = option.value;
                    return false;
                }
            });

            if (value != null) fieldArray.push({ Name: name, Value: value });
        });

        // checkbox field
        var checkboxWraps = $('.componentES_' + cid + ' .fields .checkbox_wrap');
        $.each(checkboxWraps, function(i) {
            var name = $(this).attr('title');
            var mandatory = $(this).hasClass('mandatory');
            var $checkboxes = $('.checkbox:checked', $(this));
            var values = '';

            $.each($checkboxes, function(j) {
                values += values.length > 0 ? ', ' : '';
                values += $(this).val();
            });

            if (mandatory && values.length <= 0) { valid = false; return false; } //validation
            fieldArray.push({ Name: name, Value: values });
        });

        // date field
        var dateFields = $('.componentES_' + cid + ' .fields .date');
        $.each(dateFields, function(i) {
            var name = $(this).attr('name');
            var value = $(this).val();
            var mandatory = $(this).hasClass('mandatory');
            if (mandatory && $.trim(value).length <= 0) { valid = false; return false; }
            fieldArray.push({ Name: name, Value: value });
        });

        // stop here if form is invalid
        if (!valid) {
            $('.componentES_' + cid + ' .mandatory_error').show();
            $('.svcError_' + cid).html('Fields marked with asterisks (*) are mandatory');
            return;
        } else {
            $('.componentES_' + cid + ' .mandatory_error').hide();
            $('.svcError_' + cid).html('');
        }

        // turn on ajax loader image
        $('.componentES_' + cid + ' .loader').show();

        //send via service -- (servicePath, methodName, useGet, params, onSuccess, onFailure, userContext, timeout)
        Sys.Net.WebServiceProxy.invoke('/awms/services/EmailSubscription.asmx', 'subscribeContact', false, { databaseId: dbId, customFields: fieldArray },
        function(resp) {
            $('.svcSuccess_' + cid).html('Subscription success');
            $('.componentES_' + cid + ' .loader').hide();
        }, function(err) {
            //$('.svcError_' + cid).html(err.get_message() + '<br/>' + err.get_exceptionType() + '<br/><pre>' + err.get_stackTrace() + '</pre>');
            $('.svcError_' + cid).html(err.get_message());
            $('.componentES_' + cid + ' .loader').hide();
        });
    },

    // Initialize component on load / update
    init: function(cid) {
        $.each($('.componentES_' + cid + ' .date'), function(i) {
            $(this).datepicker({ dateFormat: 'yy-mm-dd', changeYear: true });
        });
    }
};

var PortalUtility = {
    ajax: function(options) {
        args = $.extend({}, { dataType: "json", async: false, type: "POST", success: function(rep) { } }, options);

        $.ajax({
            type: args.type,
            url: args.url,
            data: args.data,
            contentType: "application/json; charset=utf-8",
            dataType: args.dataType,
            async: args.async,
            success: function(rep) {
                args.success(rep);
            }
        });
    }
}

var PortalSearch = {
    preview: function(obj, contentElementId) {
        if ($(obj).attr("href").length == 0)
            return;

        $.ajaxSetup({ async: false });

        var previewPaneContent = $("#" + contentElementId);

        previewPaneContent.text("Loading...");
        previewPaneContent.load($(obj).attr("href"));

        return false;
    }
}

var overlayHeight;
var totalItems;
var PortalPreview = {
    init: function() {
        overlayHeight = $('.componentSearchResults .columns').height();
        $('.previewOverlay').css('height', overlayHeight + "px");

        totalItems = $('.componentSearchResults .item').length;

        $('.componentSearchResults .item').each(function(index) {
            var liparent = $(this).parent('li');
            if (index == (totalItems - 1)) { $(liparent).addClass('last'); }
            $(this).find('.btnPreview').click(function() {
                $("#previewContent").html('');
                openPreview(index);
                PortalSearch.preview(this, 'previewContent');
            });
        });
        $('.componentSearchResults .previewNav .lnkClose').click(function() {
            $('.componentSearchResults .columns li').removeClass('selected');
            $('.previewHolder, .previewOverlay').hide();
            $('.connectingLine').removeAttr('style');
        });
    }
}

//Preview function: Open preview
function openPreview(index) {
    $('.componentSearchResults .columns li').removeClass('selected');
    $('.componentSearchResults .item').eq(index).parent('li').addClass('selected');
    var selectedItem = $('.componentSearchResults .columns li.selected .item');
    var liparent = $('.componentSearchResults .item').eq(index).parent('li');
    var totalItems = $('.componentSearchResults .mainResult .itemListing > li').length;
    var previewPos = 0;
    var midTotal = 0;
    if ((totalItems % 2) == 0) {//Number is even
        midTotal = (totalItems / 2) - 1;
    }
    else {//Number is odd
        midTotal = parseInt(totalItems / 2);
    }
    if (index <= midTotal) {
        previewPos = $(liparent).position().top - 40;
        $('.previewHolder').removeAttr('style').css('top', previewPos + "px");
        $('.connectingLine').css({
            'height': $(selectedItem).height() + 43 + "px",
            'top': '40px',
            'bottom': 'auto'
        }).show();
    }
    else {
        previewPos = overlayHeight - ($(liparent).position().top + $(liparent).height() + 54);
        $('.previewHolder').removeAttr('style').css('bottom', previewPos + "px");
        $('.connectingLine').css({
            'height': $(selectedItem).height() + 43 + "px",
            'top': 'auto',
            'bottom': '40px'
        }).show();
    }
    $('.previewHolder').show();
    $('.previewOverlay').show();
}
//Preview function: update connecting line position
function updateConnectingLinePosition() {
    if ($('.componentSearchResults .columns li.selected').length > 0) {
        var selectedItem = $('.componentSearchResults .columns li.selected .item');
        $('.connectingLine').css({ 'top': $(selectedItem).y() - 19 + "px" });
    }
}

function printMe() {
    //window.close("printWindow");
    $('.toPrint').remove();

    var printWindow = window.open("", "printWindow", "width=500,height=500,scrollbars=1,titlebar=1,resizable=1");
    //printWindow.moveTo($('.container').x() + 150, 200); //container width - print window width / 2

    $('#aspnetForm').append("<div class=\"toPrint\"><div class=\"stats\"></div><h1></h1></div>");
    
    var h1 = "";
    $('h1 cufontext').each(function() {
        h1 += $(this).html();
    });    
    $('.toPrint h1').html(h1);
          
    var stats = "";

    if ($('.searchCategory .selected').length > 0) {
        stats += '<strong>Category</strong>: ' + $('.searchCategory .selected').text() + "&nbsp;&nbsp;&nbsp;";
    }
    if ($('.pagingStat:eq(0)').length > 0) {
        stats += '<strong>' + $('.pagingStat:eq(0)').text() + "</strong>&nbsp;&nbsp;&nbsp;";
    }
    if ($('.pagingNav:eq(0) .currentPage').length > 0) {
        stats += '<strong>Page</strong>: ' + $('.pagingNav:eq(0) .currentPage').text();
    }

    //to avoid duplications
    if ($(".componentFavListing").length == 0) {
        //for page like privacy who consist only of .componentRTE
        $(".componentRTE").clone().appendTo($('.toPrint'));
    }
    
    //analyst listing
    $(".componentAnalystList .analystListing").clone().appendTo($('.toPrint'));

    //analystdetail
    $(".componentAnalystDetail .columns").clone().addClass('componentAnalystDetail').appendTo($('.toPrint'));

    //category intro
    $(".componentCategoryIntro .componentReadMore").clone().appendTo($('.toPrint'));
    $(".componentCategoryIntro .desc").clone().appendTo($('.toPrint'));
    $(".componentCategoryIntro .threads").clone().appendTo($('.toPrint'));
    $(".componentCategoryIntro .resources").clone().appendTo($('.toPrint'));

    //search result
    $(".componentSearchResults .heading span").clone().appendTo($('.toPrint h1'));
    $(".componentSearchResults .mainResult .itemListing").clone().appendTo($('.toPrint'));
    $(".componentSearchResults .otherResult").clone().appendTo($('.toPrint'));

    //edit profile
    $(".componentEditProfile h2").clone().appendTo($('.toPrint'));
    $(".componentEditProfile .formFieldset").clone().appendTo($('.toPrint'));

    //resource detail
    $(".componentResourceDetail .thumb").clone().appendTo($('.toPrint'));
    $(".componentResourceDetail .tabSummary").clone().removeAttr('style').appendTo($('.toPrint'));
    $(".componentResourceDetail .tabAnalyst").clone().removeAttr('style').appendTo($('.toPrint'));
    $(".componentResourceDetail .tabComment").clone().removeAttr('style').appendTo($('.toPrint'));
    $(".componentResourceDetail .relatedResource").clone().appendTo($('.toPrint'));

    //componentCommunity
    //$(".componentCommunity .containerTwoColLeft").clone().appendTo($('.toPrint'));
    $(".componentCommunity .containerThreeColLeft").clone().appendTo($('.toPrint'));
    $(".componentCommunity .containerThreeColCenter").clone().appendTo($('.toPrint'));
    $(".componentCommunity .containerThreeColRight").clone().appendTo($('.toPrint'));

    //sitemap
    $(".componentSitemap .pages .tree").clone().removeClass('quickTree').appendTo($('.toPrint'));
    $(".componentSitemap .category h2").clone().appendTo($('.toPrint'));
    $(".componentSitemap .category .tree").clone().removeClass('quickTree').appendTo($('.toPrint'));
    //$(".componentSitemap .category").clone().appendTo($('.toPrint'));

    //discussion
    $("#yafpage_forum").clone().appendTo($('.toPrint'));
    $("#yafpage_topics .tblLinkColor").clone().appendTo($('.toPrint'));
    
    $("#yafpage_posts h2").clone().appendTo($('.toPrint'));
    $("#yafpage_posts .messageList").clone().appendTo($('.toPrint'));


    if (stats.length > 0) { $('.toPrint .stats').html(stats); }
    else { $('.toPrint .stats').remove(); }

    if ($('.toPrint .tabComment').length > 0) {
        $('.toPrint .stats').appendTo($('.toPrint .tabComment h3'));
    }

    var toprint = $('.toPrint').html();
    $('.toPrint').html(toprint);
       
    //remove unnecessary print
    $('.toPrint CUFON, .toPrint cufon').removeAttr('style').removeAttr('class');
    $('.toPrint cufoncanvas, .toPrint CUFONCANVAS, .toPrint canvas, .toPrint cvml:shape, .toPrint cvml').remove();
    $('.toPrint .columns h1, .toPrint .componentReadMore .short, .toPrint .componentReadMore .lnkMore').remove();
    $('.toPrint .itemListing ul.action, .toPrint .otherResult .heading span').remove();
    $('.toPrint script, .toPrint .componentPOW').remove();
    $('.toPrint .tabComment .paging, .toPrint .tabComment .addComment').remove();
    $('.toPrint .postfooter, .toPrint .postep, .toPrint .yaflittlebutton, .toPrint .yafcssbigbutton').remove();
    $('.toPrint .containerTwoColLeft h1, .toPrint .componentRTE h1').remove();
    $('.toPrint .tree ul').removeAttr('style');
    $('.toPrint #yafpage_forum h1').remove();

    //create footnotes
    /*
    if ($('.toPrint a').length > 0) {
        $('.toPrint').append("<h2>Links</h2>");
        $('.toPrint').append("<ol id=\"footnote\"></ol>");
        var footnote = 1;
        $(".toPrint a[href]").each(function() {

            if ($(this).attr("href").indexOf('javascript') < 0) {
                $(this).append("<sup>" + footnote + "</sup>");

                if ($(this).attr("href").indexOf('http') == 0 || $(this).attr("href").indexOf('HTTP') == 0) {
                    $("#footnote").append("<li>" + $(this).attr("href") + "</li>");
                }

                else {
                    $("#footnote").append("<li>http://www.sustainabletourismonline.com" + $(this).attr("href") + "</li>");
                }
                footnote++;
            }
        });
    }
*/

    var buttons = '<div class="noPrint"><a href="javascript:window.print();" title="print">print</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="javascript:window.close();" title="close">close</a></div>';
    var stoURL = '<div class="stoURL">www.sustainabletourismonline.com</div>';
    printWindow.document.write('<html><head><title>' + h1 + '</title>');
    printWindow.document.write('<link href="/Themes/STO/css/skin_print.css" rel="stylesheet" type="text/css" />');
    printWindow.document.write('</head><body>');
    printWindow.document.write(stoURL + buttons + '<div class="content">' + $('.toPrint').html() + '</div>');
    printWindow.document.write('</body></html>');
    printWindow.document.close();
    printWindow.focus();

    return false;
}

