$(document).ready( function() {
	$('img.rollover').each( function() {
		this.onmouseover	= function() { this.src = this.src.replace("_out","_over"); }
		this.onmouseout		= function() { this.src = this.src.replace("_over","_out"); }
	} );


	$('*').each( function() {
        if( this.getAttribute("jType") != null ) {
			var typeString = "Site.Types."+this.getAttribute("jType");
			try {
				var object = eval(typeString);
				object.apply(this);
			}
			catch( ex ) {
				Page.alert( typeString + " does not exist" );
			}
		}
	} );
} );

var Variable = {
	getStringOrDefault: function( value, defaultValue ) {
		return value==null || value=="" ? defaultValue : value;
	},
	getIntOrDefault: function( value, defaultValue ) {
		return isNaN(parseInt(value)) ? defaultValue : parseInt(value);
	}
};

var Site = {
	Types: {},
	Products: {
		display: function( file ) {
            if( window.location.href.indexOf("products.php") != -1 ) {
			    $('#product_frame').attr('src','/catalog/'+file);
                window.location.hash = file;
            }
            else {
                window.location.href    = "/products.php#"+file;
            }
		}
	}
}

var Page = {
    Settings: {},

    alert: function(message, callback) {
        if (!jQuery.isReady) alert("DEVELOPER ERROR: Page.alert() cannot be used until after page load");
        if (!$('#divAlert').length) {
            $(document.body).append("<div id='divAlert' title='Alert Message:'><div id='divAlert_Message'></div><div></div>");
            $('#divAlert').dialog({
                autoOpen: false,
                modal: true,
                stack: true
            });
        }
        $('#divAlert_Message').html(message);
        $('#divAlert').dialog('option', 'buttons', { "OK": function() {
            $(this).dialog("close");
        }
        });

        $('#divAlert').unbind('dialogclose', callback); 			// unbind to avoid old callback from getting called
        if (callback != null && typeof callback == 'function') {
            $('#divAlert').bind('dialogclose', callback);
        }

        $('#divAlert').dialog('open');
    },
    confirm: function(message, onOkCallback) {
        if (!jQuery.isReady) alert("DEVELOPER ERROR: Page.confirm() cannot be used until after page load");
        if (!$('#divConfirm').length) {
            $(document.body).append("<div id='divConfirm' title='Please Confirm:'><div id='divConfirm_Message'></div><div></div>");
            $('#divConfirm').dialog({
                autoOpen: false,
                modal: true,
                stack: true
            });
        }
        $('#divConfirm_Message').html(message);
        $('#divConfirm').dialog('option', 'buttons', {
            "YES": function() {
                if (onOkCallback != null && typeof onOkCallback == 'function') {
                    onOkCallback();
                }
                $(this).dialog("close");
            },
            "NO": function() {
                $(this).dialog("close");
            }
        });

        $('#divConfirm').dialog('open');
    },
    progress: function(action) {
        if (!jQuery.isReady) alert("DEVELOPER ERROR: Page.progress() cannot be used until after page load");
        if (!$('#divProgress').length) {
            $(document.body).append("<div id='divProgress' title='Please Wait:'><div>Updating...</div><div></div>");
            $('#divProgress').dialog({
                autoOpen: false,
                modal: true,
                stack: true
            });
        }
        $('#divProgress').dialog(action);
    }
};

