/* IE6 flicker fix
-------------------------------------------------- */
try {
    document.execCommand("BackgroundImageCache", false, true);
} catch (err) { }

/*
* Author: Rob Reid
* CreateDate: 20-Mar-09
* Description: Little helper function to return details about IE 8 and its various compatibility settings either use as it is
* or incorporate into a browser object. Remember browser sniffing is not the best way to detect user-settings as spoofing is
* very common so use with caution.
*/
function IEVersion() {
    var _n = navigator, _w = window, _d = document;
    var version = "NA";
    var na = _n.userAgent;
    var ieDocMode = "NA";
    var ie8BrowserMode = "NA";
    // Look for msie and make sure its not opera in disguise
    if (/msie/i.test(na) && (!_w.opera)) {
        // also check for spoofers by checking known IE objects
        if (_w.attachEvent && _w.ActiveXObject) {
            // Get version displayed in UA although if its IE 8 running in 7 or compat mode it will appear as 7
            version = (na.match(/.+ie\s([\d.]+)/i) || [])[1];
            // Its IE 8 pretending to be IE 7 or in compat mode		
            if (parseInt(version) == 7) {
                // documentMode is only supported in IE 8 so we know if its here its really IE 8
                if (_d.documentMode) {
                    version = 8; //reset? change if you need to
                    // IE in Compat mode will mention Trident in the useragent
                    if (/trident\/\d/i.test(na)) {
                        ie8BrowserMode = "Compat Mode";
                        // if it doesn't then its running in IE 7 mode
                    } else {
                        ie8BrowserMode = "IE 7 Mode";
                    }
                }
            } else if (parseInt(version) == 8) {
                // IE 8 will always have documentMode available
                if (_d.documentMode) { ie8BrowserMode = "IE 8 Mode"; }
            }
            // If we are in IE 8 (any mode) or previous versions of IE we check for the documentMode or compatMode for pre 8 versions			
            ieDocMode = (_d.documentMode) ? _d.documentMode : (_d.compatMode && _d.compatMode == "CSS1Compat") ? 7 : 5; //default to quirks mode IE5				   			
        }
    }

    return {
        "UserAgent": na,
        "Version": version,
        "BrowserMode": ie8BrowserMode,
        "DocMode": ieDocMode
    }
}

function popup(mylink, windowname) {
    var w = 560;
    var h = 450;
    var left = (screen.width / 2) - (w / 2);
    var top = (screen.height / 2) - (h / 2);
    if (!window.focus) return true;
    window.open(mylink, windowname, 'width=' + w + ',height=' + h + ',scrollbars=no,resizable=no,location=no, top=' + top + ', left=' + left);

    return false;
}


function get_url_param(name) {
    var name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null) return "";
    else return results[1];
}

function resizeFrame(frame, padd) {
    var h = parseInt(frame.contentWindow.document.body.scrollHeight) + parseInt(padd);
    frame.style.height = h + 'px';
}

function reloadFrame(frameid) {
    var f = document.getElementById(frameid);
    f.src = f.src;
}

/* jQuery
-------------------------------------------------- */
var $j = jQuery.noConflict();

/*
var signOut = {
init : function(){
$j("div.loggedin p.exit a").click(this.clickIt);
},
clickIt : function(){
$j(this).parents("div.loggedin").hide();
$j("div.loggedout").fadeIn(400);
return false;
}
};
var closeSignoutMsg = {
init : function(){
$j("div.loggedout p.exit a").click(this.clickIt);
},
clickIt : function(){
$j(this).parents("div.loggedout").slideUp("fast");
return false;
}
};
*/

function dataHover() {
    $j("table.data tr").hover(
		function() {
		    $j(this).addClass("hover");
		},
		function() {
		    $j(this).removeClass("hover");
		}
	);
}

var ExampleInputText = {
    b: null,
    init: function() {
        //        if ((typeof (WebForm_OnSubmit) == 'function')) {
        //            this.b = WebForm_OnSubmit;
        //            WebForm_OnSubmit = this.destroy;
        //        }
        $j("input.text[example!=''][focused!='true']").each(function(i) {
            if ($j(this).val() == "") {
                $j(this).addClass("water-marker-text");
                $j(this).val($j(this).attr("example"));
            }
        });
        $j("input.text[example!='']").focus(function() {
            if ($j(this).hasClass("water-marker-text")) {
                $j(this).removeClass("water-marker-text");
                $j(this).val("");
            }
        });
        $j("input.text[example!='']").blur(function() {
            if ($j(this).val() == "") {
                $j(this).addClass("water-marker-text");
                $j(this).val($j(this).attr("example"));
            }
        });
    },
    destroy: function() {
        $j("input.water-marker-text").each(function(i) {
            $j(this).val("");
        });
        if (this.b)
            this.b();
    }
}

//var treeTable = {
//    init: function() {
//        $j('.head').click(function() {
//            $j(this).nextAll('.child').toggleClass('hidden');
//            $j(this).toggleClass('expanded');
//            $j(this).toggleClass('collapsed');
//        });
//    }
//}

var _118NotepadFrame = {
    init: function() {
        if (get_url_param('118uk') == "true" || get_url_param('118UK') == "true") {
            $j("#expand-frame-link").toggle();
            $j("#collapse-frame-link").toggle();
            $j("#promo-text").toggle();
            $j(".spacer").toggle();
            //$j("#logo").attr("id","logo-small");
            $j(".plogo").addClass("plogo-small");
            $j(".plogo").removeClass("plogo");
            //$j("#header").attr("id","header-small");
            $j(".divheader").addClass("divheader-small");
            $j(".divheader").removeClass("divheader");
            $j("#frame-div").css("display", "block");
            $j("#frame-div").css("height", "auto");
        }
        $j("#expand-frame-link").click(this.expand);
        $j("#collapse-frame-link").click(this.collapse);
    },
    expand: function() {
        reloadFrame("frame118uk");
        $j(".spacer").toggle();
        //$j("#logo").attr("id","logo-small");
        $j(".plogo").addClass("plogo-small");
        $j(".plogo").removeClass("plogo");
        //$j("#header").attr("id","header-small");
        $j(".divheader").addClass("divheader-small");
        $j(".divheader").removeClass("divheader");
        $j("#expand-frame-link").toggle();
        $j("#promo-text").toggle();
        $j("#collapse-frame-link").toggle();
        $j("#frame-div").css("display", "none");
        $j("#frame-div").css("height", "auto");
        $j("#frame-div").slideDown(1000);
    },
    collapse: function() {
        $j(".spacer").toggle();
        //$j("#logo").attr("id","logo-small");
        $j(".plogo-small").addClass("plogo");
        $j(".plogo").removeClass("plogo-small");
        //$j("#header").attr("id","header-small");
        $j(".divheader-small").addClass("divheader");
        $j(".divheader").removeClass("divheader-small");
        $j("#expand-frame-link").toggle();
        $j("#promo-text").toggle();
        $j("#collapse-frame-link").toggle();
        $j("#frame-div").slideUp(1000);
    }
};

var galleryVar = {
    init: function() {
        $j('.gallery_demo_unstyled').addClass('gallery'); // adds new class name to maintain degradability

        $j('ul.gallery').galleria({
            height:300,
            history: false, // activates the history object for bookmarking, back-button etc.
            clickNext: true, // helper for making the image clickable
            insert: '#main_image', // the containing selector for our main image
            onImage: function(image, caption, thumb) { // let's add some image effects for demonstration purposes

                // fade in the image & caption
                if (!($j.browser.mozilla && navigator.appVersion.indexOf("Win") != -1)) { // FF/Win fades large images terribly slow

                }
                image.css('display', 'none').fadeIn(1000);
                caption.css('display', 'none').fadeIn(1000);

                // fetch the thumbnail container
                var _li = thumb.parents('li');

                // fade out inactive thumbnail
                _li.siblings().children('img.selected').fadeTo(500, 0.3);

                // fade in active thumbnail
                thumb.fadeTo('fast', 1).addClass('selected');

                // add a title for the clickable image
                if (this.clickNext)
                    image.attr('title', 'Next image >>');
            },
            onThumb: function(thumb) { // thumbnail effects goes here
                // fetch the thumbnail container
                var _li = thumb.parents('li');

                // if thumbnail is active, fade all the way.
                var _fadeTo = _li.is('.active') ? '1' : '0.3';

                // fade in the thumbnail when finnished loading
                thumb.css({ display: 'none', opacity: _fadeTo }).fadeIn(1500);

                // hover effects
                thumb.hover(
					function() { thumb.fadeTo('fast', 1); },
					function() { _li.not('.active').children('img').fadeTo('fast', 0.3); } // don't fade out if the parent is active
				)
            }
        });
    }
}

/*------------- sliding ad ---------------*/
var slidingAd = {
    init: function() {
        $j(function() { //on DOM ready
            if ($j("#scroller").get() != undefined)
                $j("#scroller").simplyScroll({ autoMode: 'loop' });
        });
    }
}
var slidingAdIe6fix = {
    init: function() {
        if ($j('#ie6fix ').get(0) != undefined) {
            $j('#ie6fix ').css('position', 'absolute');
            $j(window).scroll(function() {
                var h = $j(window).height();
                //var t = h - $j('#ie6fix #scroller').height() + $j(this).scrollTop();
                var t = h + $j(this).scrollTop();
                $j('#ie6fix ').css('top', t + "px");
            });
        }
    }
}

$j(document).ready(function() {
    gadgetPromo.init();
    slidingAd.init();
    /* IE */
    if ($j.browser.msie) {
    }

    /* IE6 */
    if ($j.browser.msie && ($j.browser.version < 7)) {
        dataHover();
        slidingAdIe6fix.init();
    }

    _118NotepadFrame.init();
    galleryVar.init();
});

// calling functionality
$j(document).ready(function() {
    $j(".callLink").cluetip({
        local: true,
        positionBy: 'mouse',
        showTitle: false,
        dropShadow: false,
        mouseOutClose: true,
        tracking: true,
        attribute: 'cluetip',
        closeText: "",
        topOffset: -15,
        leftOffset: 15,
        clickThrough: true
    });
    $j(".callLink").colorbox({
        initialWidth: "580px",
        width: "580px",
        height: "400px",
        initialHeight: "400px",
        overlayClose: true,
        scrolling: false,
        iframe: true,
        opacity: 0.5,
        transition: "none"
    });
});

var gadgetPromo = {
    init: function() {

        if (((navigator.userAgent.indexOf("Windows NT 6.0") > -1) || (navigator.userAgent.indexOf("Windows NT 6.1") > -1)) && ($j.cookie('_118hideGadgetPromo') != 1))
            setTimeout(function() { $j('#gadgetPromo').slideDown('2000') }, "2000");

        $j('#gadgetPromoClose').click(function() {
            $j.cookie('_118hideGadgetPromo', '1', { domain: '', path: '/', expires: 100 });
            $j('#gadgetPromo').slideUp('2000')
        });
        $j('#gadgetPromoDownload').click(function() {
        $j.cookie('_118hideGadgetPromo', '1', { domain: '', path: '/', expires: 100 });
            setTimeout(function() {
                $j('#gadgetPromo').slideUp('2000')
            }, "2000");
        });

    }
}
