if (typeof DRP == 'undefined') {
	var DRP = {};
}

/**
 * Create a namespace for ex. DRP.admin.pages
 * @param {string} srcName The name of the namespace without for ex. "admin.pages"
 */
DRP.namespace = function(srcName) {
	var arg = arguments, name=null, obj=null, i;
	name = srcName.split('.');
	obj = DRP;
	
	for (i=0; i<name.length; i++) {
		obj[name[i]] = obj[name[i]] || {};
		obj = obj[name[i]];
	}
	
	return obj;
}

function yousure(){
	return confirm('You have selected to start over and will lose any current progress.');
}

// if you know an img is going to be a png, and know the size, this creates it right the first time for IE
function create_png(src, width, height){
	var img = $('<img/>');
	if ($.browser.msie) {
		img.attr('src', BASEPATH + 'assets/images/shim.gif');
		img.css({
			width: width,
			height: height,
			filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='crop');"
		});
	} else {
		img.attr('src', src);
	}
	return img;
}

function fix_png(){
	if (!$.browser.msie) return;

	var image = $(this);
	var src = image.attr('src');

	if (!/\.png$/i.test(src)) return; // only apply to png's
	
	setTimeout(function(){
//		var width = image.width(), height = image.height();
		
		// if the width is 0, try to re-load the image to find the width/height
//		if (!width) {
		var temp_image = new Image();
		temp_image.onload = function(){
			var width = this.width;
			var height = this.height;
			
			if (!width || !height) 
				return; // no size, can't do this fix

			image.css({
				width: width,
				height: height,
				filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='crop');"
			});
			image.attr('src', BASEPATH + 'assets/images/shim.gif');
		};
		temp_image.src = src;
	}, 1);
}

function fix_all_pngs() {
	// mark the images we've done with a class so we only deal with new ones each time
	$('img').not('.fixed-png').addClass('fixed-png').each(fix_png).load(fix_png);
}

if ($.browser.msie) {
	// turn on background image caching, preventing any flickering
	try {
		document.execCommand("BackgroundImageCache", false, true);
	} 
	catch (err) {
	}

	$(fix_all_pngs);
}

// disable right-clicking on .nosave elements
$('.nosave').live("contextmenu",function(){
	return false;
});
