﻿var objParamDefault =
{
    speedIn: 600,
    speedOut: 200,
    width: 743,
    height: 448,
    autoDimensions: false,
    autoScale: false,
    showCloseButton: false,
    enableEscapeButton: true,
    hideOnOverlayClick: true,
    overlayShow: true,
    scrolling: 'no',
    margin: 0,
    padding: 0
};

if (jQuery) 
{
    jQuery(document).ready
    (
        function() {

            jQuery('body').append('<div id="ajax_loading_overlay"><div id="ajax_loading" /></div>');

            jQuery('img.hover').each
		    (
		        function() {
		            var img = jQuery(this);

		            if (img.attr('src').indexOf('.') > -1) {


		                var iIndex = img.attr('src').lastIndexOf('.');
		                img.attr('rest', img.attr('src'));

		                if (img.attr('hover') == null && img.attr('hover') != '')
		                    img.attr('hover', img.attr('src').substr(0, iIndex) + "_hover." + img.attr('src').substr(iIndex + 1));

		                img.mouseover
		                (
		                    function() {

		                        var img = jQuery(this);

		                        img.attr('src', img.attr('hover'));
		                    }
		                );

		                img.mouseout
		                (
		                    function() {
		                        var img = jQuery(this);
		                        img.attr('src', img.attr('rest'));
		                    }
		                );
		            }
		        }
            );

            var aryTxt = jQuery('input[type="text"],textarea');

            aryTxt.blur
            (
                function() {
                    var txt = jQuery(this);

                    //remove html/script tags
                    var reTags = /<(.|\n)*?>/g;

                    txt.val(jQuery.trim(txt.val()).replace(reTags, ""));
                }
            );

            var aryTxtDefaultValue = jQuery('input[type="text"][default_value],textarea[default_value]');

            aryTxtDefaultValue.each
            (
                function() {
                    var txt = $(this);

                    var strDefault = (txt.attr("default_value") ? txt.attr("default_value") : null);

                    txt.focus
                    (
                        function() {
                            var strDefault = (txt.attr("default_value") ? txt.attr("default_value") : null);

                            if (strDefault && txt.val() == strDefault) {
                                txt.val("");
                            }
                        }
                    );

                    txt.blur
                    (
                        function() {
                            txt.val(jQuery.trim(txt.val()));

                            var strDefault = (txt.attr("default_value") ? txt.attr("default_value") : null);

                            if ((strDefault && txt.val() == "")) {
                                txt.val(strDefault);
                            }
                        }
                    );

                    txt.keypress
                    (
                        function(e) {
                            if (e.which == 13) {

                                txt.val(jQuery.trim(txt.val()));

                                var bRet = true;

                                if ((strDefault && txt.val() == strDefault) || (txt.val() == "")) {
                                    bRet = false;
                                }

                                return bRet;
                            }
                        }
                    );
                }
            );

            jQuery('a').mouseover
	        (
		        function() {
		            var a = jQuery(this);
		            a.find('img[hover]').each
			        (
				        function() {
				            var img = jQuery(this);
				            img.attr('src', img.attr('hover'));
				        }
			        );
		        }
	        );

            jQuery('a').mouseout
	        (
		        function() {
		            var a = jQuery(this);
		            a.find('img[rest]').each
			        (
				        function() {
				            var img = jQuery(this);
				            img.attr('src', img.attr('rest'));
				        }
			        );
		        }
	        );

            setDropdownEvents();

            ////////////////
            //nav toggles
            ////////////////
            jQuery(".navHide").click(function() {

                jQuery(this).css("visibility", "hidden");
                jQuery(".navBox").hide();
                jQuery(".navBox").css("visibility", "visible");
                jQuery(".navBox").fadeIn(900);

            });

            ////////////////////////////
            //home page start now button
            ////////////////////////////
            jQuery('#hpBBButton a img').each
            (
                function() {
                    var img = jQuery(this);
                    if (img.attr('class').indexOf(img.attr('activeclass')) > -1) {
                        img.attr('src', img.attr('active'));
                        img.attr('rest', img.attr('active'));
                    }
                }
            );

            jQuery('#hpBBButton a img').mouseover
	        (
	            function() {
	                var img = jQuery(this);
	                if (img.attr('rest') && img.attr('hover')) {
	                    img.attr('src', img.attr('hover'));
	                }
	            }
	        );

            jQuery('#hpBBButton a img').mouseout
	        (
	            function() {
	                var img = jQuery(this);
	                if (img.attr('rest'))
	                    img.attr('src', img.attr('rest'));
	            }
	        );

            ////////////////////////////
            //main navigation
            ////////////////////////////
            jQuery('#mainNav .left img[class][activeclass]').each
            (
                function() {
                    var img = jQuery(this);

                    if (img.attr('class').indexOf(img.attr('activeclass')) > -1) {
                        img.attr('src', img.attr('active'));
                        img.attr('rest', img.attr('active'));
                    }
                }
            );

            jQuery('#mainNav .left').mouseover
	        (
	            function() {

	                var pnl = jQuery(this);
	                var img = pnl.find('a img');

	                if (img.attr('rest') && img.attr('hover')) {
	                    img.parents('.left').css({ "z-index": "1" });
	                    img.attr('src', img.attr('hover'));

	                }

	            }
	        );

            jQuery('#mainNav .left').mouseout
	        (
	            function() {
	                var pnl = jQuery(this);
	                var img = pnl.find('a img');

	                if (img.attr('rest'))
	                    img.attr('src', img.attr('rest'));

	                img.parents('.left').css({ "z-index": '' });
	            }
	        );

            jQuery('#mainNav .left').mouseout
	        (
	            function() {
	                var pnl = jQuery(this);
	                var img = pnl.find('a img');

	                if (img.attr('rest'))
	                    img.attr('src', img.attr('rest'));

	                if (jQuery.browser.msie && jQuery.browser.version < 8.00)
	                    pnl.next('.left').css("z-index", null);
	            }
	        );

            jQuery('a.fancyb:not(.global_ignore),a.popup:not(.global_ignore),a.fancyb_fullWidth').each
		    (
		        function() {

		            var a = jQuery(this);

		            if (!a.hasClass('fancybox'))
		                a.addClass('fancybox');

		            if (!a.hasClass('iframe'))
		                a.addClass('iframe');

		            var objParams = a.attr('params') ? jQuery.extend(objParamDefault, a.attr('params').ParamsToObject()) : objParamDefault;

		            if (a.hasClass('fancyb_fullWidth')) {

		                objParams.width = 900;
		                objParams.height = 550;
		                objParams.showCloseButton = true;

		            }


		            a.fancybox(objParams);
		        }
		    );


            //this will close fb from within an iframe
            jQuery(".closefb").click(
                function() {

                    parent.jQuery.fancybox.close();
                }
            );

            bind_fancybox_parent_redirect();
            bind_fancybox_parent_open();
        }
    );
}

function setDropdownEvents()
{
    jQuery('.do_dropdown').click
    (
        function() {
            var el = jQuery(this);

            if (el.hasClass('open'))
                el.removeClass('open');
            else
                el.addClass('open');
        }
    );

    try 
    {
        /* rebind on ajax */
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest
        (
            function(sender, args) {
                jQuery('.do_dropdown').click
                (
                    function() {
                        var el = jQuery(this);

                        if (el.hasClass('open'))
                            el.removeClass('open');
                        else
                            el.addClass('open');
                    }
                );
            }
        );
    }
    catch (e) { }
}

function bind_fancybox_parent_redirect() {
    var hl = jQuery('a.fancybox_parent_redirect');

    hl.each
    (
        function() {
            var a = jQuery(this);

            if (parent.parent) {
                var strHref = a.attr("href");
                a.attr("onclick", "return window.top.window.location.href = '" + strHref + "';");
                a.attr("href", "javascript:void(0);");
                a.removeClass('fancybox_parent_redirect');
            }
        }
    );
    }
   
    function bind_fancybox_parent_open() 
    {
        var hl = jQuery('a.fancybox_parent_open');

        hl.each
        (
            function() {
                var a = jQuery(this);

                if (parent.parent) {
                    var strHref = a.attr("href");
                    var strParams = a.attr('params') ? a.attr('params') : "";

                    a.attr("href", "javascript:parentLaunchFB(this, \"" + strHref + "\", \"" + strParams + "\");");
                    a.removeClass('fancybox_parent_open');
                }
            }
        );
    }
