﻿/************************************************
* SWF Object, getUrlVar(), ScrollTo, Cookie(), LoopSlider
*************************************************/

if (typeof jQuery != 'undefined') {
    jQuery(function ($) {
        $.fn.extend({
            loopedSlider: function (options) {
                var settings = $.extend({}, $.fn.loopedSlider.defaults, options);

                return this.each(
					function () {
					    if ($.fn.jquery < '1.3.2') { return; }
					    var $t = $(this);
					    var o = $.metadata ? $.extend({}, settings, $t.metadata()) : settings;

					    var distance = 0;
					    var times = 1;
					    var slides = $(o.slides, $t).children().size();
					    var width = $(o.slides, $t).children().outerWidth();
					    var position = 0;
					    var active = false;
					    var number = 0;
					    var interval = 0;
					    var restart = 0;
					    var pagination = $("." + o.pagination + " li a", $t);

					    if (o.addPagination && !$(pagination).length) {
					        var buttons = slides;
					        $($t).append("<ul class=" + o.pagination + ">");
					        $(o.slides, $t).children().each(function () {
					            if (number < buttons) {
					                $("." + o.pagination, $t).append("<li><a rel='" + (number + 1) + "' href=\"#\" >" + (number + 1) + "</a></li>");
					                number = number + 1;
					            } else {
					                number = 0;
					                return false;
					            }
					            $("." + o.pagination + " li a:eq(0)", $t).parent().addClass("active");
					            /*==============*/
					            $("." + o.pagination + " li a:eq(0)", $t).parent().parent().parent().parent().parent().parent().removeAttr("class").addClass("p" + times);
					            try { bannerClick($($t).attr("id")); } catch (e) { }
					            /*==============*/
					        });
					        pagination = $("." + o.pagination + " li a", $t);
					    } else {
					        $(pagination, $t).each(function () {
					            number = number + 1;
					            $(this).attr("rel", number);
					            $(pagination.eq(0), $t).parent().addClass("active");
					            /*==============*/
					            $(pagination.eq(0), $t).parent().parent().parent().parent().parent().parent().removeAttr("class").addClass("p" + times);
					            try { bannerClick($($t).attr("id")) } catch (e) { }
					            /*==============*/
					        });
					    }

					    if (slides === 1) {
					        $(o.slides, $t).children().css({ position: "absolute", left: position, display: "block" });
					        return;
					    }

					    $(o.slides, $t).css({ width: (slides * width) });

					    $(o.slides, $t).children().each(function () {
					        $(this).css({ position: "absolute", left: position, display: "block" });
					        position = position + width;
					    });

					    $(o.slides, $t).children(":eq(" + (slides - 1) + ")").css({ position: "absolute", left: -width });

					    if (slides > 3) {
					        $(o.slides, $t).children(":eq(" + (slides - 1) + ")").css({ position: "absolute", left: -width });
					    }

					    if (o.autoHeight) { autoHeight(times); }

					    $(".next", $t).click(function () {
					        if (active === false) {
					            animate("next", true);
					            if (o.autoStart) {
					                if (o.restart) { autoStart(); }
					                else { clearInterval(sliderIntervalID); }
					            }
					        } return false;
					    });

					    $(".previous", $t).click(function () {
					        if (active === false) {
					            animate("prev", true);
					            if (o.autoStart) {
					                if (o.restart) { autoStart(); }
					                else { clearInterval(sliderIntervalID); }
					            }
					        } return false;
					    });

					    if (o.containerClick) {
					        $(o.container, $t).click(function () {
					            if (active === false) {
					                animate("next", true);
					                if (o.autoStart) {
					                    if (o.restart) { autoStart(); }
					                    else { clearInterval(sliderIntervalID); }
					                }
					            } return false;
					        });
					    }

					    $(pagination, $t).click(function () {
					        if ($(this).parent().hasClass("active")) { return false; }
					        else {
					            times = $(this).attr("rel");
					            $(pagination, $t).parent().siblings().removeClass("active");
					            $(this).parent().addClass("active");
					            /*==============*/
					            $(pagination, $t).parent().parent().parent().parent().parent().parent().removeAttr("class");
					            $(this).parent().parent().parent().parent().parent().parent().addClass("p" + times);
					            try { bannerClick($($t).attr("id")) } catch (e) { }
					            /*==============*/
					            animate("fade", times);
					            if (o.autoStart) {
					                if (o.restart) { autoStart(); }
					                else { clearInterval(sliderIntervalID); }
					            }
					        } return false;
					    });

					    if (o.autoStart) {
					        sliderIntervalID = setInterval(function () {
					            if (active === false) { animate("next", true); }
					        }, o.autoStart);
					        function autoStart() {
					            if (o.restart) {
					                clearInterval(sliderIntervalID);
					                clearInterval(interval);
					                clearTimeout(restart);
					                restart = setTimeout(function () {
					                    interval = setInterval(function () {
					                        animate("next", true);
					                    }, o.autoStart);
					                }, o.restart);
					            } else {
					                sliderIntervalID = setInterval(function () {
					                    if (active === false) { animate("next", true); }
					                }, o.autoStart);
					            }
					        };
					    }

					    function current(times) {
					        if (times === slides + 1) { times = 1; }
					        if (times === 0) { times = slides; }
					        $(pagination, $t).parent().siblings().removeClass("active");
					        $(pagination + "[rel='" + (times) + "']", $t).parent().addClass("active");
					        /*==============*/
					        $(pagination, $t).parent().parent().parent().parent().parent().parent().removeAttr("class");
					        $(pagination + "[rel='" + (times) + "']", $t).parent().parent().parent().parent().parent().parent().addClass("p" + times);
					        try { bannerClick($($t).attr("id")) } catch (e) { }
					        /*==============*/
					    };

					    function autoHeight(times) {
					        if (times === slides + 1) { times = 1; }
					        if (times === 0) { times = slides; }
					        var getHeight = $(o.slides, $t).children(":eq(" + (times - 1) + ")", $t).outerHeight();
					        $(o.container, $t).animate({ height: getHeight }, o.autoHeight);
					    };

					    function animate(dir, clicked) {
					        active = true;
					        switch (dir) {
					            case "next":
					                times = times + 1;
					                distance = (-(times * width - width));
					                current(times);
					                if (o.autoHeight) { autoHeight(times); }
					                if (slides < 3) {
					                    if (times === 3) { $(o.slides, $t).children(":eq(0)").css({ left: (slides * width) }); }
					                    if (times === 2) { $(o.slides, $t).children(":eq(" + (slides - 1) + ")").css({ position: "absolute", left: width }); }
					                }
					                $(o.slides, $t).animate({ left: distance }, o.slidespeed, function () {
					                    if (times === slides + 1) {
					                        times = 1;
					                        $(o.slides, $t).css({ left: 0 }, function () { $(o.slides, $t).animate({ left: distance }) });
					                        $(o.slides, $t).children(":eq(0)").css({ left: 0 });
					                        $(o.slides, $t).children(":eq(" + (slides - 1) + ")").css({ position: "absolute", left: -width });
					                    }
					                    if (times === slides) $(o.slides, $t).children(":eq(0)").css({ left: (slides * width) });
					                    if (times === slides - 1) $(o.slides, $t).children(":eq(" + (slides - 1) + ")").css({ left: (slides * width - width) });
					                    active = false;
					                });
					                break;
					            case "prev":
					                times = times - 1;
					                distance = (-(times * width - width));
					                current(times);
					                if (o.autoHeight) { autoHeight(times); }
					                if (slides < 3) {
					                    if (times === 0) { $(o.slides, $t).children(":eq(" + (slides - 1) + ")").css({ position: "absolute", left: (-width) }); }
					                    if (times === 1) { $(o.slides, $t).children(":eq(0)").css({ position: "absolute", left: 0 }); }
					                }
					                $(o.slides, $t).animate({ left: distance }, o.slidespeed, function () {
					                    if (times === 0) {
					                        times = slides;
					                        $(o.slides, $t).children(":eq(" + (slides - 1) + ")").css({ position: "absolute", left: (slides * width - width) });
					                        $(o.slides, $t).css({ left: -(slides * width - width) });
					                        $(o.slides, $t).children(":eq(0)").css({ left: (slides * width) });
					                    }
					                    if (times === 2) $(o.slides, $t).children(":eq(0)").css({ position: "absolute", left: 0 });
					                    if (times === 1) $(o.slides, $t).children(":eq(" + (slides - 1) + ")").css({ position: "absolute", left: -width });
					                    active = false;
					                });
					                break;
					            case "fade":
					                times = [times] * 1;
					                distance = (-(times * width - width));
					                current(times);
					                if (o.autoHeight) { autoHeight(times); }
					                $(o.slides, $t).children().fadeOut(o.fadespeed, function () {
					                    $(o.slides, $t).css({ left: distance });
					                    $(o.slides, $t).children(":eq(" + (slides - 1) + ")").css({ left: slides * width - width });
					                    $(o.slides, $t).children(":eq(0)").css({ left: 0 });
					                    if (times === slides) { $(o.slides, $t).children(":eq(0)").css({ left: (slides * width) }); }
					                    if (times === 1) { $(o.slides, $t).children(":eq(" + (slides - 1) + ")").css({ position: "absolute", left: -width }); }
					                    $(o.slides, $t).children().fadeIn(o.fadespeed);
					                    active = false;
					                });
					                break;
					            default:
					                break;
					        }
					    };
					}
				);
            }
        });
        $.fn.loopedSlider.defaults = {
            container: ".loop-container", //Class/id of main container. You can use "#container" for an id.
            slides: ".slides", //Class/id of slide container. You can use "#slides" for an id.
            pagination: "pagination", //Class name of parent ul for numbered links. Don't add a "." here.
            containerClick: true, //Click slider to goto next slide? true/false
            autoStart: 0, //Set to positive number for true. This number will be the time between transitions.
            restart: 0, //Set to positive number for true. Sets time until autoStart is restarted.
            slidespeed: 300, //Speed of slide animation, 1000 = 1second.
            fadespeed: 200, //Speed of fade animation, 1000 = 1second.
            autoHeight: 0, //Set to positive number for true. This number will be the speed of the animation.
            addPagination: false //Add pagination links based on content? true/false
        };
    });
}

/*
* jQuery EasIng v1.1.2 - http://gsgd.co.uk/sandbox/jquery.easIng.php
*
* Uses the built In easIng capabilities added In jQuery 1.1
* to offer multiple easIng options
*
* Copyright (c) 2007 George Smith
* Licensed under the MIT License:
*   http://www.opensource.org/licenses/mit-license.php
*/

// t: current time, b: begInnIng value, c: change In value, d: duration

jQuery.extend(jQuery.easing,
{
    easeInQuad: function (x, t, b, c, d) {
        return c * (t /= d) * t + b;
    },
    easeOutQuad: function (x, t, b, c, d) {
        return -c * (t /= d) * (t - 2) + b;
    },
    easeInOutQuad: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t + b;
        return -c / 2 * ((--t) * (t - 2) - 1) + b;
    },
    easeInCubic: function (x, t, b, c, d) {
        return c * (t /= d) * t * t + b;
    },
    easeOutCubic: function (x, t, b, c, d) {
        return c * ((t = t / d - 1) * t * t + 1) + b;
    },
    easeInOutCubic: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
        return c / 2 * ((t -= 2) * t * t + 2) + b;
    },
    easeInQuart: function (x, t, b, c, d) {
        return c * (t /= d) * t * t * t + b;
    },
    easeOutQuart: function (x, t, b, c, d) {
        return -c * ((t = t / d - 1) * t * t * t - 1) + b;
    },
    easeInOutQuart: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
        return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
    },
    easeInQuint: function (x, t, b, c, d) {
        return c * (t /= d) * t * t * t * t + b;
    },
    easeOutQuint: function (x, t, b, c, d) {
        return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
    },
    easeInOutQuint: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
        return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
    },
    easeInSine: function (x, t, b, c, d) {
        return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
    },
    easeOutSine: function (x, t, b, c, d) {
        return c * Math.sin(t / d * (Math.PI / 2)) + b;
    },
    easeInOutSine: function (x, t, b, c, d) {
        return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
    },
    easeInExpo: function (x, t, b, c, d) {
        return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
    },
    easeOutExpo: function (x, t, b, c, d) {
        return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
    },
    easeInOutExpo: function (x, t, b, c, d) {
        if (t == 0) return b;
        if (t == d) return b + c;
        if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
        return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
    },
    easeInCirc: function (x, t, b, c, d) {
        return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
    },
    easeOutCirc: function (x, t, b, c, d) {
        return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
    },
    easeInOutCirc: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
        return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
    },
    easeInElastic: function (x, t, b, c, d) {
        var s = 1.70158; var p = 0; var a = c;
        if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3;
        if (a < Math.abs(c)) { a = c; var s = p / 4; }
        else var s = p / (2 * Math.PI) * Math.asin(c / a);
        return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
    },
    easeOutElastic: function (x, t, b, c, d) {
        var s = 1.70158; var p = 0; var a = c;
        if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3;
        if (a < Math.abs(c)) { a = c; var s = p / 4; }
        else var s = p / (2 * Math.PI) * Math.asin(c / a);
        return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
    },
    easeInOutElastic: function (x, t, b, c, d) {
        var s = 1.70158; var p = 0; var a = c;
        if (t == 0) return b; if ((t /= d / 2) == 2) return b + c; if (!p) p = d * (.3 * 1.5);
        if (a < Math.abs(c)) { a = c; var s = p / 4; }
        else var s = p / (2 * Math.PI) * Math.asin(c / a);
        if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
        return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
    },
    easeInBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c * (t /= d) * t * ((s + 1) * t - s) + b;
    },
    easeOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
    },
    easeInOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
        return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
    },
    easeInBounce: function (x, t, b, c, d) {
        return c - jQuery.easing.easeOutBounce(x, d - t, 0, c, d) + b;
    },
    easeOutBounce: function (x, t, b, c, d) {
        if ((t /= d) < (1 / 2.75)) {
            return c * (7.5625 * t * t) + b;
        } else if (t < (2 / 2.75)) {
            return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
        } else if (t < (2.5 / 2.75)) {
            return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
        } else {
            return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
        }
    },
    easeInOutBounce: function (x, t, b, c, d) {
        if (t < d / 2) return jQuery.easing.easeInBounce(x, t * 2, 0, c, d) * .5 + b;
        return jQuery.easing.easeOutBounce(x, t * 2 - d, 0, c, d) * .5 + c * .5 + b;
    }
});
/*
* jQuery spritely 0.5
* http://spritely.net/
*
* Documentation:
* http://spritely.net/documentation/
*
* Copyright 2010-2011, Peter Chater, Artlogic Media Ltd, http://www.artlogic.net/
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Change history:
* Version 0.5
*   - added a 'destroy()' method which will stop the element's sprite behaviour, without actually removing the element. Example: $('#my_sprite').destroy()
* Version 0.4
*   - add up/down for 'pan' method. <ricky.hewitt@artlogic.net>
*   - added 'dir' option for Sprites. This means a Sprite can be played in reverse.
*   - removed alert message regarding jQuery.draggable (now uses console.log, if available) <ricky.hewitt@artlogic.net>
* Version 0.3b
*   - added lockTo method for locking sprites to background images. $('#sprite').lockTo('#background, {'left': 380, 'top': -60, 'bg_img_width': 1110});
* Version 0.2.1
*   - animate function will stop cycling after play_frames has completed
* Version 0.2 beta
*   - added isDraggable method (requires jquery-ui) $('#sprite').sprite().isDraggable({start: null, stop: function() {alert('Ouch! You dropped me!')});
*   - sprites may be set to play a limited number of frames when instantiated, e.g. $('#sprite').sprite({fps: 9, no_of_frames: 3, play_frames: 30})
*   - sprite speed may be controlled at any point by setting the frames-per-second $('#sprite').fps(20);
*   - sprites with multiple rows of frames may have there 'state' changed, e.g. to make the second row of frames
*     active, use: $('#sprite').spState(2); - to return to the first row, use $('#sprite').spState(1);
*   - background element speed may be controlled at any point with .spSpeed(), e.g. $('#bg1').spSpeed(10)
*   - background elements may be set to a depth where 100 is the viewer (up close) and 0 is the horizon, e.g.:
*     $('#bg1').pan({fps: 30, speed: 2, dir: 'left', depth: 30});
*     $('#bg2').pan({fps: 30, speed: 3, dir: 'left', depth: 70});
*     relative speed of backgrounds may now be set in a single action with $('#bg1, #bg2').spRelSpeed(20);
*     which will make elements closer to the horizon (lower depths) move slower than closer elements (higher depths)
*/

(function ($) {
    $._spritely = {
        // shared methods and variables used by spritely plugin
        animate: function (options) {
            var el = $(options.el);
            var el_id = el.attr('id');
            if (!$._spritely.instances[el_id]) {
                return this;
            }
            options = $.extend(options, $._spritely.instances[el_id] || {});
            if (options.play_frames && !$._spritely.instances[el_id]['remaining_frames']) {
                $._spritely.instances[el_id]['remaining_frames'] = options.play_frames + 1;
            }
            if (options.type == 'sprite' && options.fps) {
                var frames;
                var animate = function (el) {
                    var w = options.width, h = options.height;
                    if (!frames) {
                        frames = [];
                        total = 0
                        for (var i = 0; i < options.no_of_frames; i++) {
                            frames[frames.length] = (0 - total);
                            total += w;
                        }
                    }

                    if (options.rewind == true) {
                        if ($._spritely.instances[el_id]['current_frame'] <= 0) {
                            $._spritely.instances[el_id]['current_frame'] = frames.length - 1;
                        } else {
                            $._spritely.instances[el_id]['current_frame'] = $._spritely.instances[el_id]['current_frame'] - 1;
                        };
                    } else {
                        if ($._spritely.instances[el_id]['current_frame'] >= frames.length - 1) {
                            $._spritely.instances[el_id]['current_frame'] = 0;
                        } else {
                            $._spritely.instances[el_id]['current_frame'] = $._spritely.instances[el_id]['current_frame'] + 1;
                        }
                    }

                    var yPos = $._spritely.getBgY(el);
                    el.css('background-position', frames[$._spritely.instances[el_id]['current_frame']] + 'px ' + yPos);
                    if (options.bounce && options.bounce[0] > 0 && options.bounce[1] > 0) {
                        var ud = options.bounce[0]; // up-down
                        var lr = options.bounce[1]; // left-right
                        var ms = options.bounce[2]; // milliseconds
                        el
							.animate({ top: '+=' + ud + 'px', left: '-=' + lr + 'px' }, ms)
							.animate({ top: '-=' + ud + 'px', left: '+=' + lr + 'px' }, ms);
                    }
                }
                if ($._spritely.instances[el_id]['remaining_frames'] && $._spritely.instances[el_id]['remaining_frames'] > 0) {
                    $._spritely.instances[el_id]['remaining_frames']--;
                    if ($._spritely.instances[el_id]['remaining_frames'] == 0) {
                        $._spritely.instances[el_id]['remaining_frames'] = -1;
                        delete $._spritely.instances[el_id]['remaining_frames'];
                        return;
                    } else {
                        animate(el);
                    }
                } else if ($._spritely.instances[el_id]['remaining_frames'] != -1) {
                    animate(el);
                }
            } else if (options.type == 'pan') {
                if (!$._spritely.instances[el_id]['_stopped']) {
                    if (options.dir == 'up') {
                        $._spritely.instances[el_id]['l'] = $._spritely.getBgX(el).replace('px', '');
                        $._spritely.instances[el_id]['t'] = ($._spritely.instances[el_id]['t'] - (options.speed || 1)) || 0;
                    }
                    else if (options.dir == 'down') {
                        $._spritely.instances[el_id]['l'] = $._spritely.getBgX(el).replace('px', '');
                        $._spritely.instances[el_id]['t'] = ($._spritely.instances[el_id]['t'] + (options.speed || 1)) || 0;
                    }
                    else if (options.dir == 'left') {
                        $._spritely.instances[el_id]['l'] = ($._spritely.instances[el_id]['l'] - (options.speed || 1)) || 0;
                        $._spritely.instances[el_id]['t'] = $._spritely.getBgY(el).replace('px', '');
                    } else {
                        $._spritely.instances[el_id]['l'] = ($._spritely.instances[el_id]['l'] + (options.speed || 1)) || 0;
                        $._spritely.instances[el_id]['t'] = $._spritely.getBgY(el).replace('px', '');
                    }

                    // When assembling the background-position string, care must be taken
                    // to ensure correct formatting.. <ricky.hewitt@artlogic.net>
                    var bg_left = $._spritely.instances[el_id]['l'].toString();
                    if (bg_left.indexOf('%') == -1) {
                        bg_left += 'px ';
                    } else { bg_left += ' '; }

                    var bg_top = $._spritely.instances[el_id]['t'].toString();
                    if (bg_top.indexOf('%') == -1) {
                        bg_top += 'px ';
                    } else { bg_top += ' '; }

                    $(el).css('background-position', bg_left + bg_top);
                }
            }
            $._spritely.instances[el_id]['options'] = options;
            window.setTimeout(function () {
                $._spritely.animate(options);
            }, parseInt(1000 / options.fps));
        },
        randomIntBetween: function (lower, higher) {
            return parseInt(rand_no = Math.floor((higher - (lower - 1)) * Math.random()) + lower);
        },
        getBgY: function (el) {
            if ($.browser.msie) {
                // fixme - the background-position property does not work
                // correctly in IE so we have to hack it here... Not ideal
                // especially as $.browser is depricated
                var bgY = $(el).css('background-position-y') || '0';
            } else {
                var bgY = ($(el).css('background-position') || ' ').split(' ')[1];
            }
            return bgY;
        },
        getBgX: function (el) {
            if ($.browser.msie) {
                // see note, above
                var bgX = $(el).css('background-position-x') || '0';
            } else {
                var bgX = ($(el).css('background-position') || ' ').split(' ')[0];
            }
            return bgX;
        },
        get_rel_pos: function (pos, w) {
            // return the position of an item relative to a background
            // image of width given by w
            var r = pos;
            if (pos < 0) {
                while (r < 0) {
                    r += w;
                }
            } else {
                while (r > w) {
                    r -= w;
                }
            }
            return r;
        }
    };
    $.fn.extend({
        spritely: function (options) {
            var options = $.extend({
                type: 'sprite',
                do_once: false,
                width: null,
                height: null,
                fps: 12,
                no_of_frames: 2,
                stop_after: null
            }, options || {});
            var el_id = $(this).attr('id');
            if (!$._spritely.instances) {
                $._spritely.instances = {};
            }
            if (!$._spritely.instances[el_id]) {
                $._spritely.instances[el_id] = { current_frame: -1 };
            }
            $._spritely.instances[el_id]['type'] = options.type;
            $._spritely.instances[el_id]['depth'] = options.depth;
            options.el = this;
            options.width = options.width || $(this).width() || 100;
            options.height = options.height || $(this).height() || 100;
            var get_rate = function () {
                return parseInt(1000 / options.fps);
            }
            if (!options.do_once) {
                window.setTimeout(function () {
                    $._spritely.animate(options);
                }, get_rate(options.fps));
            } else {
                $._spritely.animate(options);
            }
            return this; // so we can chain events
        },
        sprite: function (options) {
            var options = $.extend({
                type: 'sprite',
                bounce: [0, 0, 1000] // up-down, left-right, milliseconds
            }, options || {});
            return $(this).spritely(options);
        },
        pan: function (options) {
            var options = $.extend({
                type: 'pan',
                dir: 'left',
                continuous: true,
                speed: 1 // 1 pixel per frame
            }, options || {});
            return $(this).spritely(options);
        },
        flyToTap: function (options) {
            var options = $.extend({
                el_to_move: null,
                type: 'moveToTap',
                ms: 1000, // milliseconds
                do_once: true
            }, options || {});
            if (options.el_to_move) {
                $(options.el_to_move).active();
            }
            if ($._spritely.activeSprite) {
                if (window.Touch) { // iphone method see http://cubiq.org/remove-onclick-delay-on-webkit-for-iphone/9 or http://www.nimblekit.com/tutorials.html for clues...
                    $(this)[0].ontouchstart = function (e) {
                        var el_to_move = $._spritely.activeSprite;
                        var touch = e.touches[0];
                        var t = touch.pageY - (el_to_move.height() / 2);
                        var l = touch.pageX - (el_to_move.width() / 2);
                        el_to_move.animate({
                            top: t + 'px',
                            left: l + 'px'
                        }, 1000);
                    };
                } else {
                    $(this).click(function (e) {
                        var el_to_move = $._spritely.activeSprite;
                        $(el_to_move).stop(true);
                        var w = el_to_move.width();
                        var h = el_to_move.height();
                        var l = e.pageX - (w / 2);
                        var t = e.pageY - (h / 2);
                        el_to_move.animate({
                            top: t + 'px',
                            left: l + 'px'
                        }, 1000);
                    });
                }
            }
            return this;
        },
        // isDraggable requires jQuery ui
        isDraggable: function (options) {
            if ((!$(this).draggable)) {
                //console.log('To use the isDraggable method you need to load jquery-ui.js');
                return this;
            }
            var options = $.extend({
                type: 'isDraggable',
                start: null,
                stop: null,
                drag: null
            }, options || {});
            var el_id = $(this).attr('id');
            if (!$._spritely.instances[el_id]) {
                return this;
            }
            $._spritely.instances[el_id].isDraggableOptions = options;
            $(this).draggable({
                start: function () {
                    var el_id = $(this).attr('id');
                    $._spritely.instances[el_id].stop_random = true;
                    $(this).stop(true);
                    if ($._spritely.instances[el_id].isDraggableOptions.start) {
                        $._spritely.instances[el_id].isDraggableOptions.start(this);
                    }
                },
                drag: options.drag,
                stop: function () {
                    var el_id = $(this).attr('id');
                    $._spritely.instances[el_id].stop_random = false;
                    if ($._spritely.instances[el_id].isDraggableOptions.stop) {
                        $._spritely.instances[el_id].isDraggableOptions.stop(this);
                    }
                }
            });
            return this;
        },
        active: function () {
            // the active sprite
            $._spritely.activeSprite = this;
            return this;
        },
        activeOnClick: function () {
            // make this the active script if clicked...
            var el = $(this);
            if (window.Touch) { // iphone method see http://cubiq.org/remove-onclick-delay-on-webkit-for-iphone/9 or http://www.nimblekit.com/tutorials.html for clues...
                el[0].ontouchstart = function (e) {
                    $._spritely.activeSprite = el;
                };
            } else {
                el.click(function (e) {
                    $._spritely.activeSprite = el;
                });
            }
            return this;
        },
        spRandom: function (options) {
            var options = $.extend({
                top: 50,
                left: 50,
                right: 290,
                bottom: 320,
                speed: 4000,
                pause: 0
            }, options || {});
            var el_id = $(this).attr('id');
            if (!$._spritely.instances[el_id]) {
                return this;
            }
            if (!$._spritely.instances[el_id].stop_random) {
                var r = $._spritely.randomIntBetween;
                var t = r(options.top, options.bottom);
                var l = r(options.left, options.right);
                $('#' + el_id).animate({
                    top: t + 'px',
                    left: l + 'px'
                }, options.speed)
            }
            window.setTimeout(function () {
                $('#' + el_id).spRandom(options);
            }, options.speed + options.pause)
            return this;
        },
        makeAbsolute: function () {
            // remove an element from its current position in the DOM and
            // position it absolutely, appended to the body tag.
            return this.each(function () {
                var el = $(this);
                var pos = el.position();
                el.css({ position: "absolute", marginLeft: 0, marginTop: 0, top: pos.top, left: pos.left })
					.remove()
					.appendTo("body");
            });

        },
        spSet: function (prop_name, prop_value) {
            var el_id = $(this).attr('id');
            $._spritely.instances[el_id][prop_name] = prop_value;
            return this;
        },
        spGet: function (prop_name, prop_value) {
            var el_id = $(this).attr('id');
            return $._spritely.instances[el_id][prop_name];
        },
        spStop: function (bool) {
            $(this).each(function () {
                var el_id = $(this).attr('id');
                $._spritely.instances[el_id]['_last_fps'] = $(this).spGet('fps');
                $._spritely.instances[el_id]['_stopped'] = true;
                $._spritely.instances[el_id]['_stopped_f1'] = bool;
                if ($._spritely.instances[el_id]['type'] == 'sprite') {
                    $(this).spSet('fps', 0);
                }
                if (bool) {
                    // set background image position to 0
                    var bp_top = $._spritely.getBgY($(this));
                    $(this).css('background-position', '0 ' + bp_top);
                }
            });
            return this;
        },
        spStart: function () {
            $(this).each(function () {
                var el_id = $(this).attr('id');
                var fps = $._spritely.instances[el_id]['_last_fps'] || 12;
                $._spritely.instances[el_id]['_stopped'] = false;
                if ($._spritely.instances[el_id]['type'] == 'sprite') {
                    $(this).spSet('fps', fps);
                }
            });
            return this;
        },
        spToggle: function () {
            var el_id = $(this).attr('id');
            var stopped = $._spritely.instances[el_id]['_stopped'] || false;
            var stopped_f1 = $._spritely.instances[el_id]['_stopped_f1'] || false;
            if (stopped) {
                $(this).spStart();
            } else {
                $(this).spStop(stopped_f1);
            }
            return this;
        },
        fps: function (fps) {
            $(this).each(function () {
                $(this).spSet('fps', fps);
            });
            return this;
        },
        spSpeed: function (speed) {
            $(this).each(function () {
                $(this).spSet('speed', speed);
            });
            return this;
        },
        spRelSpeed: function (speed) {
            $(this).each(function () {
                var rel_depth = $(this).spGet('depth') / 100;
                $(this).spSet('speed', speed * rel_depth);
            });
            return this;
        },
        spChangeDir: function (dir) {
            $(this).each(function () {
                $(this).spSet('dir', dir);
            });
            return this;
        },
        spState: function (n) {
            $(this).each(function () {
                // change state of a sprite, where state is the vertical
                // position of the background image (e.g. frames row)
                var yPos = ((n - 1) * $(this).height()) + 'px';
                var xPos = $._spritely.getBgX($(this));
                var bp = xPos + ' -' + yPos;
                $(this).css('background-position', bp);
            });
            return this;
        },
        lockTo: function (el, options) {
            $(this).each(function () {
                var el_id = $(this).attr('id');
                if (!$._spritely.instances[el_id]) {
                    return this;
                }
                $._spritely.instances[el_id]['locked_el'] = $(this);
                $._spritely.instances[el_id]['lock_to'] = $(el);
                $._spritely.instances[el_id]['lock_to_options'] = options;
                window.setInterval(function () {
                    if ($._spritely.instances[el_id]['lock_to']) {
                        var locked_el = $._spritely.instances[el_id]['locked_el'];
                        var locked_to_el = $._spritely.instances[el_id]['lock_to'];
                        var locked_to_options = $._spritely.instances[el_id]['lock_to_options'];
                        var locked_to_el_w = locked_to_options.bg_img_width;
                        var locked_to_el_h = locked_to_el.height();
                        var locked_to_el_y = $._spritely.getBgY(locked_to_el);
                        var locked_to_el_x = $._spritely.getBgX(locked_to_el);
                        var el_l = (parseInt(locked_to_el_x) + parseInt(locked_to_options['left']));
                        var el_t = (parseInt(locked_to_el_y) + parseInt(locked_to_options['top']));
                        el_l = $._spritely.get_rel_pos(el_l, locked_to_el_w);
                        $(locked_el).css({
                            'top': el_t + 'px',
                            'left': el_l + 'px'
                        });
                    }
                }, options.interval || 20);
            });
            return this;
        },
        destroy: function () {
            var el = $(this);
            var el_id = $(this).attr('id');
            delete $._spritely.instances[el_id]
            return this;
        }
    })
})(jQuery);
// Stop IE6 re-loading background images continuously
try {
    document.execCommand("BackgroundImageCache", false, true);
} catch (err) { } 


/**
* jQuery.ScrollTo - Easy element scrolling using jQuery.
* Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
* Dual licensed under MIT and GPL.
* Date: 5/25/2009
* @author Ariel Flesler
* @version 1.4.2
*
* http://flesler.blogspot.com/2007/10/jqueryscrollto.html
*/
; (function (d) { var k = d.scrollTo = function (a, i, e) { d(window).scrollTo(a, i, e) }; k.defaults = { axis: 'xy', duration: parseFloat(d.fn.jquery) >= 1.3 ? 0 : 1 }; k.window = function (a) { return d(window)._scrollable() }; d.fn._scrollable = function () { return this.map(function () { var a = this, i = !a.nodeName || d.inArray(a.nodeName.toLowerCase(), ['iframe', '#document', 'html', 'body']) != -1; if (!i) return a; var e = (a.contentWindow || a).document || a.ownerDocument || a; return d.browser.safari || e.compatMode == 'BackCompat' ? e.body : e.documentElement }) }; d.fn.scrollTo = function (n, j, b) { if (typeof j == 'object') { b = j; j = 0 } if (typeof b == 'function') b = { onAfter: b }; if (n == 'max') n = 9e9; b = d.extend({}, k.defaults, b); j = j || b.speed || b.duration; b.queue = b.queue && b.axis.length > 1; if (b.queue) j /= 2; b.offset = p(b.offset); b.over = p(b.over); return this._scrollable().each(function () { var q = this, r = d(q), f = n, s, g = {}, u = r.is('html,body'); switch (typeof f) { case 'number': case 'string': if (/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)) { f = p(f); break } f = d(f, this); case 'object': if (f.is || f.style) s = (f = d(f)).offset() } d.each(b.axis.split(''), function (a, i) { var e = i == 'x' ? 'Left' : 'Top', h = e.toLowerCase(), c = 'scroll' + e, l = q[c], m = k.max(q, i); if (s) { g[c] = s[h] + (u ? 0 : l - r.offset()[h]); if (b.margin) { g[c] -= parseInt(f.css('margin' + e)) || 0; g[c] -= parseInt(f.css('border' + e + 'Width')) || 0 } g[c] += b.offset[h] || 0; if (b.over[h]) g[c] += f[i == 'x' ? 'width' : 'height']() * b.over[h] } else { try { var o = f[h]; g[c] = o.slice && o.slice(-1) == '%' ? parseFloat(o) / 100 * m : o } catch (e) { } } if (/^\d+$/.test(g[c])) g[c] = g[c] <= 0 ? 0 : Math.min(g[c], m); if (!a && b.queue) { if (l != g[c]) t(b.onAfterFirst); delete g[c] } }); t(b.onAfter); function t(a) { r.animate(g, j, b.easing, a && function () { a.call(this, n, b) }) } }).end() }; k.max = function (a, i) { var e = i == 'x' ? 'Width' : 'Height', h = 'scroll' + e; if (!d(a).is('html,body')) return a[h] - d(a)[e.toLowerCase()](); var c = 'client' + e, l = a.ownerDocument.documentElement, m = a.ownerDocument.body; return Math.max(l[h], m[h]) - Math.min(l[c], m[c]) }; function p(a) { return typeof a == 'object' ? a : { top: a, left: a} } })(jQuery);

//<![CDATA[
/**
* Cookie plugin
*
* Copyright (c) 2006 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/

/**
* Create a cookie with the given name and value and other optional parameters.
*
* @example $.cookie('the_cookie', 'the_value');
* @desc Set the value of a cookie.
* @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
* @desc Create a cookie with all available options.
* @example $.cookie('the_cookie', 'the_value');
* @desc Create a session cookie.
* @example $.cookie('the_cookie', null);
* @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
*       used when the cookie was set.
*
* @param String name The name of the cookie.
* @param String value The value of the cookie.
* @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
* @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
*                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
*                             If set to null or omitted, the cookie will be a session cookie and will not be retained
*                             when the the browser exits.
* @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
* @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
* @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
*                        require a secure protocol (like HTTPS).
* @type undefined
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/

/**
* Get the value of a cookie with the given name.
*
* @example $.cookie('the_cookie');
* @desc Get the value of a cookie.
*
* @param String name The name of the cookie.
* @return The value of the cookie.
* @type String
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/
jQuery.cookie = function (name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

/**
* URL QueryString Plugin
*
* Copyright (c) 2010
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
jQuery.extend({
    getUrlVars: function () {
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for (var i = 0; i < hashes.length; i++) {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    },
    getUrlVar: function (name) {
        return jQuery.getUrlVars()[name];
    }
});

// jQuery SWFObject v1.1.1 MIT/GPL @jon_neal
// http://jquery.thewikies.com/swfobject
(function (f, h, i) { function k(a, c) { var b = (a[0] || 0) - (c[0] || 0); return b > 0 || !b && a.length > 0 && k(a.slice(1), c.slice(1)) } function l(a) { if (typeof a != g) return a; var c = [], b = ""; for (var d in a) { b = typeof a[d] == g ? l(a[d]) : [d, m ? encodeURI(a[d]) : a[d]].join("="); c.push(b) } return c.join("&") } function n(a) { var c = []; for (var b in a) a[b] && c.push([b, '="', a[b], '"'].join("")); return c.join(" ") } function o(a) { var c = []; for (var b in a) c.push(['<param name="', b, '" value="', l(a[b]), '" />'].join("")); return c.join("") } var g = "object", m = true; try { var j = i.description || function () { return (new i("ShockwaveFlash.ShockwaveFlash")).GetVariable("$version") } () } catch (p) { j = "Unavailable" } var e = j.match(/\d+/g) || [0]; f[h] = { available: e[0] > 0, activeX: i && !i.name, version: { original: j, array: e, string: e.join("."), major: parseInt(e[0], 10) || 0, minor: parseInt(e[1], 10) || 0, release: parseInt(e[2], 10) || 0 }, hasVersion: function (a) { a = /string|number/.test(typeof a) ? a.toString().split(".") : /object/.test(typeof a) ? [a.major, a.minor] : a || [0, 0]; return k(e, a) }, encodeParams: true, expressInstall: "expressInstall.swf", expressInstallIsActive: false, create: function (a) { if (!a.swf || this.expressInstallIsActive || !this.available && !a.hasVersionFail) return false; if (!this.hasVersion(a.hasVersion || 1)) { this.expressInstallIsActive = true; if (typeof a.hasVersionFail == "function") if (!a.hasVersionFail.apply(a)) return false; a = { swf: a.expressInstall || this.expressInstall, height: 137, width: 214, flashvars: { MMredirectURL: location.href, MMplayerType: this.activeX ? "ActiveX" : "PlugIn", MMdoctitle: document.title.slice(0, 47) + " - Flash Player Installation"}} } attrs = { data: a.swf, type: "application/x-shockwave-flash", id: a.id || "flash_" + Math.floor(Math.random() * 999999999), width: a.width || 320, height: a.height || 180, style: a.style || "" }; m = typeof a.useEncode !== "undefined" ? a.useEncode : this.encodeParams; a.movie = a.swf; a.wmode = a.wmode || "opaque"; delete a.fallback; delete a.hasVersion; delete a.hasVersionFail; delete a.height; delete a.id; delete a.swf; delete a.useEncode; delete a.width; var c = document.createElement("div"); c.innerHTML = ["<object ", n(attrs), ">", o(a), "</object>"].join(""); return c.firstChild } }; f.fn[h] = function (a) { var c = this.find(g).andSelf().filter(g); /string|object/.test(typeof a) && this.each(function () { var b = f(this), d; a = typeof a == g ? a : { swf: a }; a.fallback = this; if (d = f[h].create(a)) { b.children().remove(); b.html(d) } }); typeof a == "function" && c.each(function () { var b = this; b.jsInteractionTimeoutMs = b.jsInteractionTimeoutMs || 0; if (b.jsInteractionTimeoutMs < 660) b.clientWidth || b.clientHeight ? a.call(b) : setTimeout(function () { f(b)[h](a) }, b.jsInteractionTimeoutMs + 66) }); return c } })(jQuery, "flash", navigator.plugins["Shockwave Flash"] || window.ActiveXObject);




/****************
* Logging Plugin
*****************/
(function ($) {
    $.fn.debug = function (value) {
        nowtime = (new Date()).getTime();

        if ($(this).data("gai." + value) == "1") {
            $(this).data("gai." + value, "0");
            oldtime = $(this).data("gai.time." + value);
            difftime = (nowtime - oldtime);
            try { console.timeEnd(value); } catch (e) {
                try { console.log("end:[ " + value + " ]: " + difftime + "ms"); } catch (e) { }
            }
        }
        else {
            $(this).data("gai." + value, "1");
            $(this).data("gai.time." + value, nowtime);
            try { console.time(value); } catch (e) {
                //try { debug("start:[ " + value + " ]"); } catch (e) { }
            }
        }
    };
    $.fn.log = function (value) {
        try { console.log("log:[ " + value + " ]"); } catch (e) { }
    };
})(jQuery);




// Stop IE6 re-loading background images continuously
try {
    document.execCommand("BackgroundImageCache", false, true);
} catch (err) { }


//~INIT
var $j = jQuery.noConflict();

var gai = {};

/**
* --------------------------------------------------------------------
* jQuery tree plugin
* Author: Scott Jehl, scott@filamentgroup.com
* Copyright (c) 2009 Filament Group 
* licensed under MIT (filamentgroup.com/examples/mit-license.txt)
* --------------------------------------------------------------------
*/
$j.fn.tooltip = function () {
    //add body role
    if (!$j('body').is('[role]')) { $j('body').attr('role', 'application'); }
    return $j(this).each(function () {
        if ($j(this).is('[data-hrefpreview],[title],[href^=#]')) {

            //generate a unique ID for the tooltip
            var ttID = 'tooltip-' + Math.round(Math.random() * 10000);
            //create tooltip container
            var tooltip = $j('<div class="tooltip" role="tooltip" id="' + ttID + '"></div>');

            //populate tooltip with content, depending on source
            if ($j(this).is('[data-hrefpreview]')) { //use ajax to retrieve data if data-hrefpreview attr is present
                tooltip.load($j(this).attr('data-hrefpreview'));
            }
            else if ($j(this).is('[href^=#]')) { //if local anchor, grab referenced content
                tooltip.append($j($j(this).attr('href')));
            }
            else if ($j(this).is('[title]')) { //if title attr is present, use that
                tooltip.html($j(this).attr('title'));
            }


            //apply attrs and events to tooltipped element			
            $j(this)
				.removeAttr('title') //remove redundant title attr
				.attr('aria-describedby', ttID) //associate tooltip with element for screenreaders
				.mousemove(function (e) {
				    var vy = -10; var vx = -10;
				    if ($j(this).attr("id") == "vid1-img") { vy = 60; vx = 70; }
				    else if ($j(this).attr("id") == "vid2-img") { vy = 60; vx = 70; }
				    else if ($j(this).attr("id") == "vid3-img") { vy = 60; vx = 90; }

				    if (tooltip.hasClass('tooltip-hidden')) {
				        tooltip
						    .appendTo('body')
						    .removeClass('tooltip-hidden')
						    .attr('aria-hidden', false)
						    .css({
						        top: e.pageY - tooltip.outerHeight() + vy,
						        left: e.pageX - vx
						    }); $debug("mousemove");
				    }
				    else {
				        tooltip
						    .css({
						        top: e.pageY - tooltip.outerHeight() + vy,
						        left: e.pageX - vx
						    });
				    }
				})
                .mouseout(function () {
                    tooltip.addClass('tooltip-hidden').attr('aria-hidden', true); $debug("mouseleave");
                });

            //find an associated form field and set its describedby attr as well for a11y
            $j('#' + $j(this).attr('for')).attr('aria-describedby', ttID);

            //append the tooltip to the page with hidden class applied
            tooltip
				.addClass('tooltip-hidden')
				.attr('aria-hidden', true)
				.appendTo('body');
        }
    });
};

//~DEBUGGER SCRIPT
var debugLineNumber = 1;
function $get(id) { return document.getElementById(id); }
function $getDebugLine() {
    return "Line " + debugLineNumber + " : ";
}
function $debug(value) {
    value = "[GAI(Debug Mode)] : " + value;

    if ($j.browser.mozilla) {
        try { console.log(value); } catch (e) { }
        try { debug(value); } catch (e) { }
    }
    else {
        try { console.log(value); } catch (e) { }
        try { debug(value); } catch (e) { }
    }
}
function $debugtimer(start, value) {
    if ($j.browser.mozilla && start) {
        try { console.time(value); } catch (e) {
            try { debug("start:[ " + value + " ]"); } catch (e) { }
        }
    }
    else if ($j.browser.mozilla) {
        try { console.timeEnd(value); } catch (e) {
            try { debug("end:[ " + value + " ]"); } catch (e) { }
        }
    }
    else {
        try { console.log(value); } catch (e) {
            try { debug(value); } catch (e) { }
        }
    }
}
//~END


/**/
function initNavigation() {
    $j(function () {
        $debug("initNavigation()");

        if (!$j("body").hasClass("IE")) {
            $j("#main-nav .nav .hover").animate({ opacity: 0 }, { queue: false, duration: 350, complete: function () { $j(this).css("visibility", "visible"); } });
            $j("#main-nav .nav").mouseenter(function () {
                $j(this).find(".hover").animate({ opacity: 1 }, { queue: false, duration: 350, complete: function () { $j(this).removeAttr("style"); } });
                //for submenu
                if ($j(this).attr("id") == "navi2") { $j("#dd2").addClass("isOn"); initSubNavigationOver("#dd2"); }
                if ($j(this).attr("id") == "navi7") { $j("#dd7").addClass("isOn"); initSubNavigationOver("#dd7"); }
            }).mouseleave(function () {

                //for submenu
                if ($j(this).attr("id") == "navi2") { $j("#dd2").removeClass("isOn"); setTimeout("checkHideDropDown('#dd2')", 200); }
                else if ($j(this).attr("id") == "navi7") { $j("#dd7").removeClass("isOn"); setTimeout("checkHideDropDown('#dd7')", 200); }
                else { $j(this).find(".hover").animate({ opacity: 0 }, { queue: false, duration: 350 }); }
            });
        }
        else {
            $j("#main-nav .nav .hover").removeAttr("style");
            $j("#main-nav .nav").mouseenter(function () {
                //for submenu
                $j(this).addClass("isIEHover");
                if ($j(this).attr("id") == "navi2") { $j("#dd2").addClass("isOn"); initSubNavigationOver("#dd2"); }
                if ($j(this).attr("id") == "navi7") { $j("#dd7").addClass("isOn"); initSubNavigationOver("#dd7"); }
            }).mouseleave(function () {
                //for submenu
                if ($j(this).attr("id") == "navi2") { $j("#dd2").removeClass("isOn"); setTimeout("checkHideDropDown('#dd2')", 200); }
                else if ($j(this).attr("id") == "navi7") { $j("#dd7").removeClass("isOn"); setTimeout("checkHideDropDown('#dd7')", 200); }
                else { $j(this).removeClass("isIEHover"); }
            });
        }

        $j("#dropdown-wrapper .dropper").mouseenter(function () {
            //for submenu
            initSubNavigationOver("#" + $j(this).attr("id"));
            $j("#" + $j(this).attr("id")).addClass("onDropdown");
        }).mouseleave(function () {
            //for submenu
            $j("#" + $j(this).attr("id")).removeClass("onDropdown");
            setTimeout("checkHideDropDown('#" + $j(this).attr('id') + "')", 200);
        });

        $j("<img />").attr("src", "http://static.the-emagination.com/siloso/images/home/dropdown-143x40.png");
        $j("<img />").attr("src", "http://static.the-emagination.com/siloso/images/home/dropdown-93x35.png");
    });
}

function initGAIButton(cid) {
    $j(function () {
        $j(this).debug("initGAIButton()");
        if (typeof (cid) == "undefined") { cid = ""; }
        if (typeof (defxpos) == "undefined") { defxpos = "left"; }

        var gid = 1;
        var type = "3";
        var defbg = "1";
        var defxpos = "left";
        var hoverposition = "center";
        var downposition = "right";
        var upposition = "left";
        var buttontext = "";
        var staticMove = false;

        if ($j.browser.safari && document.readyState != "complete") {
            $debug("initGAIButton():waiting to load...");
            setTimeout(arguments.callee, 100);
            return;
        }

        $j(cid + ".gai-button").each(function () {
            if (!$j(this).hasClass("gai-loading")) {
                var $this = this;
                var randomkey = ($j("body").hasClass("IE")) ? ("?" + new Date().getTime()) : "";
                $debug("initGAIButton():" + $j($this).parent().css("display") + $j("img", $this).width());

                if (($j($this).parent().css("display") != "none") && ($j("img", $this).width() > 2)) {
                    $j($this).addClass("gai-loading");
                    $j("<img />").attr("src", ($j("img", $this).attr("src") + randomkey)).load(function () {
                        handlerGAIButton($this, gid);
                        if ($j("body").hasClass("IE") || $j($this).hasClass("gai-switch")) { $j($this).css("background-position", "-99999px"); }
                    });
                }
            }
        });
        $j(".gai-hide").removeClass("gai-hide");

        $j(this).debug("initGAIButton()");
    });
}

function handlerGAIButton($this, gid) {
    try { type = ($j("img", $this).attr("alt").indexOf("type:2") != -1 ? "2" : "3"); } catch (e) { type = "3"; }
    try { defbg = ($j("img", $this).attr("alt").indexOf("defbg:2") != -1 ? "2" : "1"); } catch (e) { defbg = "1"; }
    var defxpos = ($j($this).hasClass('gai-hover-side') ? (type == "2" ? "right" : "center") : "left");
    var hoverposition = (type == "2" ? "right" : "center");
    var downposition = (type == "2" ? "left" : "right");
    var upposition = (type == "2" ? "left" : "left");
    var buttontext = ($j($this).attr("rel") == "textbutton" ? $j($this).attr("title") : "");
    var staticMove = $j($this).hasClass("gai-static");

    $j($this).css("display", "inline-block")
    .css("width", ($j("img", $this).width() / type) + (($j("body").hasClass("IE7")) ? 2 : 0) + "px")
    .css("height", ($j("img", $this).height()) + (($j("body").hasClass("IE7")) ? 4 : 0) + "px")
    .css("line-height", ($j("img", $this).height()) + "px")
    .css("background", "url(" + ($j("img", $this).attr("src")) + ") no-repeat left top")
    .css("text-align", "center")
    .css("cursor", "pointer")
    .html("<span class='gai-abs gai-layer2' style='" + $j($this).attr("style") + ";left:0; top:0;' gaiDataType='" + type + "'>" + buttontext + "</span>")
    .append("<span class='gai-abs gai-layer1' style='" + $j($this).attr("style") + ";left:0; top:0;' gaiDataType='" + type + "'>" + buttontext + "</span>")
    .css("background-position", defxpos + " top")/**/
    .mouseenter(function () {
        $j($this).debug(".gai-button:mouseenter");
        var xpos = ($j("span.gai-layer1", $this).attr('gaiDataType') == "2" ? "right" : "center");
        $j("span.gai-layer1", $this).css("background-position", xpos + " top");
        ($j("body").hasClass("IE") || staticMove) ? $j("span.gai-layer2", $this).css("visibility", "hidden") : $j("span.gai-layer1", $this).animate({ "opacity": "1" }, { queue: false, duration: 300 });
        ($j("body").hasClass("IE") || staticMove) ? $j("span.gai-layer1", $this).css("visibility", "visible") : $j("span.gai-layer2", $this).animate({ "opacity": "0" }, { queue: false, duration: 300 });
        $j($this).debug(".gai-button:mouseenter");
    })
    .mouseleave(function () {
        $j(this).debug(".gai-button:mouseleave");
        //var xpos = ($j('span', this).attr('gaiDataType') == "2" ? "left" : "left");
        var xpos = ($j($this).hasClass('gai-hover-side') ? (type == "2" ? "right" : "center") : "left");
        ($j("body").hasClass("IE") || staticMove) ? $j("span.gai-layer2", $this).css("visibility", "visible") : $j("span.gai-layer1", $this).animate({ "opacity": "0" }, { queue: false, duration: 300 });
        ($j("body").hasClass("IE") || staticMove) ? $j("span.gai-layer1", $this).css("visibility", "hidden") : $j("span.gai-layer2", $this).animate({ "opacity": "1" }, { queue: false, duration: 300 });
        //($j("body").hasClass("IE")) ? $j("span", this).css("visibility", "visible").parent().css("background-position", xpos + " top") : $j("span", this).animate({ "opacity": "1" }, { queue: false, duration: 300, complete: function () { $j(this).parent().css("background-position", xpos + " top"); } });
        $j($this).debug(".gai-button:mouseleave");
    })
    .mousedown(function () {
        $j("span.gai-layer1", $this).css("background-position", "right top");
    })
    .mouseup(function () {
        var xpos = ($j('span.gai-layer1', $this).attr('gaiDataType') == "2" ? "right" : "center");
        $j("span.gai-layer1", $this).css("background-position", xpos + " top");
    });
    

    //Check whether is it absolute or relative
    if (($j($this).css("position") != "absolute") && (!$j($this).hasClass("gai-abs"))) { $j($this).css("position", "relative"); }

    if ($j($this).hasClass("gai-prehidden")) {
        $j($this).addClass("gai-prehidden-loaded");
        initAnimate();
    }

    //Final to clear button and reset
    $j($this).removeClass("gai-button")
    .removeClass("gai-loading")
    .addClass("gai-button-" + (Math.floor(Math.random() * 99) + 10) + "" + gid + "" + (Math.floor(Math.random() * 99) + 10));


    //$debug($j(this).attr("style"));
    //$debug($j("img", this).width());
    //$debug($j("img", this).height());
    //$debug($j("img", this).attr("src"));
}

//function initGAIButton() {
//    $j(function () {
//        $j(this).debug("initGAIButton()");
//        if (typeof (defxpos) == "undefined") { defxpos = 2; }

//        var gid = 1;
//        var type = ($j('img', this).attr('alt').indexOf('type:2') != -1 ? "2" : "3");
//        var defbg = ($j('img', this).attr('alt').indexOf('defbg:2') != -1 ? "2" : "1");
//        var defxpos = ($j(this).hasClass('gai-hover-side') ? (type == "2" ? "right" : "center") : "left");
//        var hoverposition = (type == "2" ? "right" : "center");
//        var downposition = (type == "2" ? "left" : "right");
//        var upposition = (type == "2" ? "left" : "left");
//        var buttontext = "";
//        var duration = 300;
//        var defbackground = "";

//        $j(".gai-button").each(function () {

//            if ($j("body").hasClass("IE")) { }
//            if (typeof ($j(this).attr('gai-duration')) == "undefined") { duration = 300; }

//            type = ($j('img', this).attr('alt').indexOf('type:2') != -1 ? "2" : "3");
//            defxpos = ($j(this).hasClass('gai-hover-side') ? (type == "2" ? "right" : "center") : "left");
//            hoverposition = (type == "2" ? "right" : "center");
//            downposition = (type == "2" ? "left" : "right");
//            upposition = (type == "2" ? "left" : "left");
//            buttontext = ($j(this).attr('rel') == "textbutton" ? $j(this).attr('title') : "");

//            $j(this).css("display", "inline-block")
//            .css("width", ($j('img', this).width() / type) + (($j("body").hasClass("IE7")) ? 2 : 0) + "px")
//            .css("height", ($j('img', this).height()) + (($j("body").hasClass("IE7")) ? 4 : 0) + "px")
//            .css("line-height", ($j('img', this).height()) + "px")
//            .css("background", "url(" + ($j('img', this).attr('src')) + ") no-repeat left top")
//            .css("text-align", "center")
//            .css("cursor", "pointer")
//            .html("<span class='gai-abs gai-layer1' style='" + $j(this).attr("style") + ";left:0; top:0;' gaiDataType='" + type + "'>" + buttontext + "</span>")
//            .append("<span class='gai-abs gai-layer2' style='" + $j(this).attr("style") + ";left:0; top:0;' gaiDataType='" + type + "'>" + buttontext + "</span>")
//            .css("background-position", defxpos + " top")/**/
//            .mouseenter(function () {
//                $j(this).debug(".gai-button:mouseenter");
//                var xpos = ($j("span.gai-layer1", this).attr('gaiDataType') == "2" ? "right" : "center");
//                $j("span.gai-layer1", this).css("background-position", xpos + " top");
//                ($j("body").hasClass("IE")) ? $j("span.gai-layer1", this).css("visibility", "visible") : $j("span.gai-layer1", this).animate({ "opacity": "1" }, { queue: false, duration: 250 });
//                ($j("body").hasClass("IE")) ? $j("span.gai-layer2", this).css("visibility", "hidden") : $j("span.gai-layer2", this).animate({ "opacity": "0" }, { queue: false, duration: 250 });
//                $j(this).debug(".gai-button:mouseenter");
//            })
//            .mouseleave(function () {
//                $j(this).debug(".gai-button:mouseleave");
//                //var xpos = ($j('span', this).attr('gaiDataType') == "2" ? "left" : "left");
//                var xpos = ($j(this).hasClass('gai-hover-side') ? (type == "2" ? "right" : "center") : "left");
//                ($j("body").hasClass("IE")) ? $j("span.gai-layer1", this).css("visibility", "hidden") : $j("span.gai-layer1", this).animate({ "opacity": "0" }, { queue: false, duration: 250 });
//                ($j("body").hasClass("IE")) ? $j("span.gai-layer2", this).css("visibility", "visible") : $j("span.gai-layer2", this).animate({ "opacity": "1" }, { queue: false, duration: 250 });
//                //($j("body").hasClass("IE")) ? $j("span", this).css("visibility", "visible").parent().css("background-position", xpos + " top") : $j("span", this).animate({ "opacity": "1" }, { queue: false, duration: 300, complete: function () { $j(this).parent().css("background-position", xpos + " top"); } });
//                $j(this).debug(".gai-button:mouseleave");
//            })
//            .mousedown(function () {
//                $j("span.gai-layer1", this).css("background-position", "right top");
//            })
//            .mouseup(function () {
//                var xpos = ($j('span.gai-layer1', this).attr('gaiDataType') == "2" ? "right" : "center");
//                $j("span.gai-layer1", this).css("background-position", xpos + " top");
//            })
//            .removeClass("gai-button")
//            .addClass("gai-button-" + (Math.floor(Math.random() * 99) + 10) + "" + gid + "" + (Math.floor(Math.random() * 99) + 10))
//            .css("background", "none");

//            if (($j(this).css("position") != "absolute") && (!$j(this).hasClass("gai-abs"))) { $j(this).css("position", "relative"); }

//            //$debug($j(this).attr("style"));
//            //$debug($j("img", this).width());
//            //$debug($j("img", this).height());
//            //$debug($j("img", this).attr("src"));
//        });
//        $j(".gai-hide").removeClass("gai-hide");

//        $j("#sponsor-link").mouseenter(function () {
//            $j(this).animate({ "top": "-180", "height": "185" }, { queue: false, duration: 500, easing: "easeOutCubic" });
//        })
//        .mouseleave(function () {
//            $j(this).animate({ "top": "-32", "height": "120" }, { queue: false, duration: 500, easing: "easeOutCubic" });
//        });
//        $j(this).debug("initGAIButton()");


//        //!!!!!!!!!!!!!!!!!!!!!!!!!!!
//        $j("#fadeout-left").html("<span></span>");
//        $j("#fadeout-right").html("<span></span>");
//        $j("body").attr("defheight", $j("body").height());
//        $j(window).resize(function () {
//            checkWindowScope();
//        });
//        checkWindowScope();
//    });
//}

var defOutLeftWidth = "11%";
var defOutRightWidth = "11%";
var defOutMaxWidth = 1300;

function checkWindowScope() {
    $j(function () {
        var defBodyHeight = $j("body").attr("defheight");
        var tmpwidth = $j(window).width();
        var tmpheight = $j(window).height();
        if ((tmpwidth > defOutMaxWidth) && ((tmpwidth - defOutMaxWidth) > 143)) {
            $j("#fadeout-left").width(13 + (tmpwidth - defOutMaxWidth));
            $j("#fadeout-right").width(13 + (tmpwidth - defOutMaxWidth));
        }
        else if (tmpwidth <= 1024) {
            $j("#fadeout-left").width("0");
            $j("#fadeout-right").width("0");
        }
        else {
            $j("#fadeout-left").width(defOutLeftWidth);
            $j("#fadeout-right").width(defOutRightWidth);
        }
        $j("#fadeout-left").height(defBodyHeight);
        $j("#fadeout-right").height(defBodyHeight);

        if (tmpheight > defBodyHeight) {
            $j("#footer-holder").height(83 + (tmpheight - defBodyHeight));
        }
        else {
            $j("#footer-holder").height(83);
        }
    });
}

function GAINaviHover(xpos) {
    $j(function () {
        $j(this).debug("GAINaviHover()");

        $j(".dropdown1-content").animate({ top: xpos }, { queue: false, easing: "easeOutCubic", duration: 500 });
        ($j("body").hasClass("IE")) ? $j(".dropdown1 span").css("visibility", "hidden") : $j(".dropdown1 span").animate({ "opacity": "0" }, { queue: false, duration: 300 });

        $j(this).debug("GAINaviHover()");
    });
}
function GAINaviOut() {
    $j(function () {
        $j(this).debug("GAINaviOut()");

        $j(".dropdown1-content").animate({ top: -94 }, { queue: false, easing: "easeOutCubic", duration: 500 });
        ($j("body").hasClass("IE")) ? $j(".dropdown1 span").css("visibility", "visible") : $j(".dropdown1 span").animate({ "opacity": "1" }, { queue: false, duration: 300 });

        $j(this).debug("GAINaviOut()");
    });
}



function initButton(cls, ver, ypos) {
    $j(function () {
        $debug("initButton()");
        if (typeof (ver) == "undefined") { ver = 2; }
        if (typeof (ypos) == "undefined") { ypos = "top"; }

        if ($j("body").hasClass("IE")) {
            //For IE style
            //$j(cls).find("span").animate({ opacity: 0 }, { queue: false, duration: 350, complete: function () { $j(this).css("visibility", "visible"); } });
            $j(cls).mouseenter(function () {
                $j(this).find("span").css("visibility", "visible");
            }).mouseleave(function () {
                $j(this).find("span").css("visibility", "hidden");
            });
            if (ver == 3) {
                $j(cls).mouseleave(function () {
                    $j(this).find("span").css("visibility", "hidden");
                    $j(this).find("span").css("background-position", "center " + ypos);
                }).mousedown(function () {
                    $j(this).find("span").css("background-position", "right " + ypos);
                });
                $j(cls).find("span").css("visibility", "hidden").css("background-position", "center " + ypos);
            }
        }
        else {

            $j(cls).mouseenter(function () {
                $j(this).find("span").animate({ opacity: 1 }, { queue: false, duration: 350, complete: function () { } });
            }).mouseleave(function () {
                $j(this).find("span").animate({ opacity: 0 }, { queue: false, duration: 350 });
            });
            if (ver == 3) {
                $j(cls).mouseleave(function () {
                    $j(this).find("span").animate({ opacity: 0 }, { queue: false, duration: 350 });
                    $j(this).find("span").css("background-position", "center " + ypos);
                }).mousedown(function () {
                    $j(this).find("span").css("background-position", "right " + ypos);
                });
            }

            $j(cls).find("span").animate({ opacity: 0 }, { queue: false, duration: 350,
                complete: function () {
                    $j(this).css("visibility", "visible");

                }
            });

        }

    });
}



// [Siloso Beach Party] - Facebook Live Stream
var isFirstLiveStream = true;
function addFacebookLiveStream() {
    //$j("body").append('<div id="facebookstream"><a class="puller"><span style="visibility:hidden;"></span></a><iframe src="http://www.facebook.com/plugins/live_stream_box.php?app_id=171441419543373&amp;width=400&amp;height=443&amp;via_url&amp;always_post_to_friends=false" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:400px; height:443px;" allowTransparency="true"></iframe></div>');
    //$j("body").append('<div id="facebookstream"><a class="puller"><span style="visibility:hidden;"></span></a><iframe src="http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2FSBPofficial&amp;width=400&amp;colorscheme=dark&amp;connections=20&amp;stream=true&amp;header=false&amp;height=555" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:400px; height:555px;" allowTransparency="true"></iframe></div>');
    $j("body").append('<div id="facebookstream"><a class="puller"><span style="visibility:hidden;"></span></a></div>');
    $j("#facebookstream .puller").click(function () {
        if (isFirstLiveStream) { isFirstLiveStream = false; $j("#facebookstream").append('<iframe src="http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2FSBPofficial&amp;width=400&amp;colorscheme=dark&amp;connections=20&amp;stream=true&amp;header=false&amp;height=555" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:400px; height:555px;" allowTransparency="true"></iframe>'); }
        if ($j(this).parent().hasClass("ishover")) {
            $j(this).parent().animate({ left: -400 }, { queue: false, duration: 250, easing: 'easeOutCubic', complete: function () { } });
            $j(this).parent().removeClass("ishover");
        }
        else {
            $j(this).parent().animate({ left: 0 }, { queue: false, duration: 250, easing: 'easeOutCubic', complete: function () { } });
            $j(this).parent().addClass("ishover");
        }
    });
    initButton(".puller", 2);
}


// [Siloso Beach Party] - Header Title
function addHeaderTitle(txt) {
    var str = document.title;
    if (typeof (txt) == "undefined") { str = str.replace("Siloso Beach Party! : ", ""); }
    else { str = txt; }

    $j("#top-header-holder .container").append('<div id="titlebar"><p>You are at:</p><h2>' + str + '</h2></div>');
}


function initSubNavigationOver(id) {
    $j(function () {
        $debug("initSubNavigationOver()");

        if (!$j(id).hasClass("onAnimateOver")) {
            if (!$j(id).hasClass("onDropdown")) {
                $j(id).addClass("onAnimateOver");

                $j("#dropdown-wrapper " + id).css("display", "inline-block");
                var iheight = $j("#dropdown-wrapper " + id + " .sub-wrap").height();

                $j("#dropdown-wrapper " + id + " .drop-wrapper").animate({ top: 0 }, { queue: false, duration: 150,
                    complete: function () {
                        $j("#dropdown-wrapper " + id + " .drop-wrapper")
                        .animate({ top: 0 }, { queue: false, duration: 150 })
                        .find(".submenu").animate({ height: iheight }, { queue: false, duration: 150/*, easing:'easeOutElastic'*/ });
                        $j(id).removeClass("onAnimateOver");
                    }
                }); //.find(".submenu").animate({ height: 0 }, { queue: false, duration: 250, easing: 'easeOutCubic' });

                if (!$j("body").hasClass("IE")) {
                    if (id == "#dd2") { $j("#main-nav #navi2").find(".hover").animate({ opacity: 1 }, { queue: false, duration: 350, complete: function () { $j(this).removeAttr("style"); } }); }
                    else if (id == "#dd7") { $j("#main-nav #navi7").find(".hover").animate({ opacity: 1 }, { queue: false, duration: 350, complete: function () { $j(this).removeAttr("style"); } }); }
                }
                else {
                    if (id == "#dd2") { $j("#main-nav #navi2").addClass("isIEHover"); }
                    else if (id == "#dd7") { $j("#main-nav #navi7").addClass("isIEHover"); }
                }
            }
        }

    });
}

function initSubNavigationHide(id) {
    $j(function () {
        $debug("initSubNavigationHide()");

        if (!$j(id).hasClass("onAnimateHide")) {
            $j(id).addClass("onAnimateHide");

            $j("#dropdown-wrapper " + id + " .drop-wrapper").find(".submenu").animate({ height: 0 }, { queue: false, duration: 250,
                complete: function () {
                    $j("#dropdown-wrapper " + id + " .drop-wrapper")
                    .animate({ top: -75 }, { queue: false, duration: 250, easing: 'easeOutCubic' })
                    .find(".submenu").animate({ height: 0 }, { queue: false, duration: 250, easing: 'easeOutCubic',
                        complete: function () {
                            $j(id).removeClass("onAnimateHide");
                            if (!$j(id).hasClass("isOn") && !$j(id).hasClass("onDropdown") && !$j(id).hasClass("onAnimateHide") && !$j(id).hasClass("onAnimateOver")) { $j("#dropdown-wrapper " + id).css("display", "none"); }
                        }
                    });

                }
            });

            if (!$j("body").hasClass("IE")) {
                if (id == "#dd2") { $j("#main-nav #navi2").find(".hover").animate({ opacity: 0 }, { queue: false, duration: 350 }); }
                else if (id == "#dd7") { $j("#main-nav #navi7").find(".hover").animate({ opacity: 0 }, { queue: false, duration: 350 }); }
            }
            else {
                if (id == "#dd2") { $j("#main-nav #navi2").removeClass("isIEHover"); }
                else if (id == "#dd7") { $j("#main-nav #navi7").removeClass("isIEHover"); }
            }

        }
        //$j("#dropdown-wrapper " + id + " .drop-wrapper").animate({ top: 0 }, { queue: false, duration: 250, easing: 'easeOutCubic' });

    });
}

function checkHideDropDown(id) {
    $j(function () {
        $debug("checkDropDown()");

        if (!$j(id).hasClass("isOn") && !$j(id).hasClass("onDropdown")) { initSubNavigationHide(id); }
    });
}

function backtotop() {
    $j.scrollTo('body', 800);
    if ($j.browser.webkit) {
        //window.scrollTo(0, 0);
        $j.scrollTo('#top-header-menu', 800);
    }
}


/* Validation Scripts */
// +Varaibles
var focusField = "";

// +Functions
function isAlpha(id) {
    var field = $j("#" + id);
    var argvalue = $j("#" + id).val();
    argvalue = argvalue.toString();
    var validChars = "/0123456789. +-)(";
    for (var n = 0; n < argvalue.length; n++) {
        if (validChars.indexOf(argvalue.substring(n, n + 1)) == -1) {
            field.addClass("error"); isBlankFocus(id); return false;
        }
    }
    if (!isRequired(id)) {
        field.addClass("error"); isBlankFocus(id); return false;
    }
    field.removeClass("error");
    return true;
}

function isEmail(id) {
    var field = $j("#" + id);
    var str = $j("#" + id).val();
    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)

    if (str == "" || str == "Your email address") { field.addClass("error"); isBlankFocus(id); return false; }
    if (str.indexOf(at) == -1) { field.addClass("error"); isBlankFocus(id); return false; }
    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) { field.addClass("error"); isBlankFocus(id); return false; }
    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) { field.addClass("error"); isBlankFocus(id); return false; }
    if (str.indexOf(at, (lat + 1)) != -1) { field.addClass("error"); isBlankFocus(id); return false; }
    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) { field.addClass("error"); isBlankFocus(id); return false; }
    if (str.indexOf(dot, (lat + 2)) == -1) { field.addClass("error"); isBlankFocus(id); return false; }
    if (str.indexOf(" ") != -1) { field.addClass("error"); isBlankFocus(id); return false; }
    field.removeClass("error");
    return true;
}

function isDate(dateStr) {
    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
    var matchArray = dateStr.match(datePat); // is the format ok?
    if (matchArray == null) { alert("Please enter date as either dd/mm/yyyy or dd-mm-yyyy."); return false; }
    day = matchArray[1]; // p@rse date into variables
    month = matchArray[3];
    year = matchArray[5];
    if (month < 1 || month > 12) { alert("Month must be between 1 and 12."); return false; } // check month range 
    if (day < 1 || day > 31) { alert("Day must be between 1 and 31."); return false; }
    if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) { alert("Month " + month + " doesn`t have 31 days!"); return false; }
    if (month == 2) { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day == 29 && !isleap)) { alert("February " + year + " doesn`t have " + day + " days!"); return false; }
    }
    return true; // date is valid
}
function isBlankFocus(ans) { if (focusField == "") { focusField = ans; } }
function removeError(id) {
    $j("#" + id).removeClass("error");
    return true;
}
function isMaxNum(id, num) {
    var field = $j("#" + id);
    if (parseFloat(field.val()) > num) { field.addClass("error"); isBlankFocus(id); return false; }
    field.removeClass("error");
    return true;
}
function isRequired(id) {
    var field = $j("#" + id);
    if (field.val() == "") { field.addClass("error"); isBlankFocus(id); return false; }
    field.removeClass("error");
    return true;
}
function isLength(id, length) {
    var field = $j("#" + id);
    if (field.val().length != length) { field.addClass("error"); isBlankFocus(id); return false; }
    field.removeClass("error");
    return true;
}
function isSelection(id) {
    var field = $j("#" + id);
    if ($j("#" + id + " :selected").val() == "-1") { field.addClass("error"); isBlankFocus(id); return false; }
    else if ($j("#" + id + " :selected").val() == "Others") {
        if (!isRequired(id + "-text")) {
            field.addClass("error"); isBlankFocus(id); return false;
        }
        else if (!isRequired(id + "_text")) {
            field.addClass("error"); isBlankFocus(id); return false;
        }
    }
    field.removeClass("error");
    return true;
}
function goFocus(id) {
    //$j("#" + id).focus();
    try {
        $j.scrollTo("#" + id, 800, { offset: { top: -20} });
        focusField = "";
    }
    catch (e) {
        document.location = "#inner-meta-top";
        focusField = "";
    }
}


//var isFirstLiveStream = true;
function postScriptInit() {
    initGAIButton();
    initNewsHolder();

    $j("#hightlights-wrapper .puller").click(function () {
        //if (isFirstLiveStream) { isFirstLiveStream = false; $j("#facebookstream").append('<iframe src="http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2FSBPofficial&amp;width=400&amp;colorscheme=dark&amp;connections=20&amp;stream=true&amp;header=false&amp;height=555" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:400px; height:555px;" allowTransparency="true"></iframe>'); }
        if ($j(this).parent().hasClass("ishover")) {
            $j(this).parent().animate({ left: -753 }, { queue: false, duration: 250, easing: 'easeOutCubic', complete: function () { } });
            $j(this).parent().removeClass("ishover");
            $j("#bg-fader").css("display","none");
        }
        else {
            $j(this).parent().animate({ left: -10 }, { queue: false, duration: 250, easing: 'easeOutCubic', complete: function () { } });
            $j(this).parent().addClass("ishover");
            $j("#bg-fader").css("display", "inline-block");

        }
    });
}
//~[NAVIGATION SCRIPT]
var _timerOffNavigation;
var _currentContent;

function initNavigation() {
    $j(function () {
        $j(".expand-navi").each(function () {
            $j(this).addClass($j(this).attr("rel"));
        });

        $j(".expand-navi").mousedown(function () {
            $debug("initNavigation(.expand-navi):mouseenter");
            clearNavigationTimer();
            $j("#navigation-inner .hover").removeClass("hover");
            $j("#navigation-wrapper").animate({ height: 160 }, { duration: 600, queue: false, easing: "easeOutExpo" });
            //$j("#navigation-wrapper .behind").animate({ top: -60 }, { duration: 300, queue: false, easing: "easeOutExpo" });
            //$j("#navigation-wrapper .behind." + $j(this).attr("rel")).animate({ top: 50 }, { duration: 300, queue: false, easing: "easeInExpo" });
            $j("#navigation-wrapper .behind:not(." + $j(this).attr("rel") + ")").fadeOut(300);
            $j("#navigation-wrapper .behind." + $j(this).attr("rel")).fadeIn(300);
            $j("#navigation-inner ." + $j(this).attr("rel")).addClass("hover");
            _currentContent = $j(this).attr("rel");
            $j("#top-header-holder").removeAttr("class").addClass(_currentContent);
        }).mouseleave(function () {
            $debug("initNavigation(.expand-navi):mouseleave");
            //closeNavigationTimer();
        });
        $j("#navigation-wrapper .behind").mouseenter(function () {
            $debug("initNavigation(#navigation-wrapper .behind):mouseenter");

            clearNavigationTimer();
        });
        $j("#navigation-wrapper").mouseleave(function () {
            $debug("initNavigation(#navigation-wrapper):mouseleave");
            closeNavigationTimer();
        });
        $j("#navigation-wrapper .behind").fadeOut(300);

        initGAIButton();
    });
}
function clearNavigationTimer() { clearTimeout(_timerOffNavigation); }
function closeNavigationTimer() { _timerOffNavigation = setTimeout("closeNavigation()", 500); }
function closeNavigation() {
    //$j("#navigation-wrapper .behind." + _currentContent).animate({ top: -60 }, { duration: 300, queue: false, easing: "easeOutExpo" });
    $j("#navigation-wrapper .behind." + _currentContent).fadeOut(300);
    $j("#navigation-wrapper").animate({ height: 40 }, { duration: 500, queue: false });
    $j("#navigation-inner .hover").removeClass("hover");
    $j("#top-header-holder").removeAttr("class");
}

/*[News Holder]*/
function initNewsHolder() {
    $j("#news-holder .container .block").mouseover(function () {
        $j(this).addClass("mhover");
    }).mouseout(function () {
        $j(this).removeClass("mhover");
    });
}

//]]>
