var bCommon = {
	toggle: function(what) {
		$('#' + what).toggle(250);
		return;
	},
	
	breakBackButton: function() {
		window.onbeforeunload = function(e) { return "You will lose any changes which have not been saved!"; };
		return;	
	},
	
	restoreBackButton: function(){
		window.onbeforeunload = null;
		return;
	},
	
	getTime: function() {
		return (new Date()).getTime();
	},
	
	imageHoverMagic: function() {
		if(this.src.match(/-hover\.png$/)) this.src = this.src.replace(/-hover\.png$/,'.png');
		else this.src = this.src.replace(/\.png$/,'-hover.png');
		return;	
	},
	
	windowScrollToTop: function() {
		jQuery(window).scrollTop(0);
		return;	
	},
	
	scrollThisDown: function(what) {
		if(jQuery(what).length) {
			var obj = jQuery(what).get(0);
		} else {
			return false;
		}
			
		obj.scrollTop = obj.scrollHeight;	
		return;
	},

	
	//. tired of remembering which methods you should pass jquery style id to and which
	//. you should just specifiy standalone? lets make a new rule right now, never pass
	//. jquery style id. methods should use this when getting their arguments or whatever
	//. to force into whatever style id they need.
	jqid: function(what,bejq) {
		if(bejq && !what.match(/^#/)) return "#" + what;
		else if(!bejq && what.match(/^#/)) return what.replace(/^#/,'');
		
		return what;
	},
	
	breakLineWrap: function(text) {
	
		text = text.replace(/ /g,'&nbsp;').replace(/-/g,'&#8209;');
	
		return text;
	},
	
	ajaxURL: function(url) {
		return url + '/' + bCommon.getTime();
	}
};

//. these are safe bindings for shorter code.
var getTime = bCommon.getTime;
var ajaxURL = bCommon.ajaxURL;

//. these are legacy bindings.
//. referecnes to these should be migrated to bCommon and removed.
//. 20090120 - bob
var breakBackButton = bCommon.breakBackButton;
var restoreBackButton = bCommon.restoreBackButton;
var imageHoverMagic = bCommon.imageHoverMagic;
var windowScrollToTop = bCommon.windowScrollToTop;
var ShowAndHideDiv = bCommon.toggle;

/* global variable object for cross whatever scripting. sometimes it is just
 * 10x simpler if the javascript does not have to do any special thinking at
 * use run time. this gets initialized before document ready so that the order
 * of scripts does not matter (other than this being first lol) */
var globalVar = {
	'domain': null,
	'subdomain': null,
	'domainHome': null,
	
	'lightview':null,
	
	init: function() {	
		globalVar.domain = document.domain.match(/[^\.]+\.[^\.]+$/);
		globalVar.subdomain = document.domain.match(/^[^\.]+/);		
		globalVar.domainHome = 'www.' + globalVar.domain;	
		return;
	}
}; globalVar.init();

/* global variable object for knowing what the mouse is doing. this will be
 * most awesomely useful at times. */
var theMouse = {
	'x':0,
	'y':1
};

/* things we want to do when every page load is done. */
jQuery(document).ready(function(){
	jQuery('img.magic')
		.mouseover(imageHoverMagic)
		.mouseout(imageHoverMagic);
		
	jQuery(document).mousemove(function(e) {
		theMouse.x = e.pageX;
		theMouse.y = e.pageY;
	});
});

jQuery(document).ready(function() {
	//. generate a warning to show the user if they are using an older browser.
	//. notice for the ie warning i didn't even make a firefox joke, i suggested
	//. they update not switch.
	if(jQuery.browser.msie) {
		switch(jQuery.browser.version.substr(0,1)) {
			case "5": { }
			case "6": {
				$('div#main-content').prepend(
					'<div class="firmpage-msg"><div class="error">It appears you are using '+
					'a <em>really old</em> version of Internet Explorer. To get the full Blogster experience '+
					'<b>as well as for your online safety</b> you should update your browser '+
					'to Internet Explorer 7 or 8.</div></div>'
				); break;
			}
		}
	}
	

/*
	setTimeout(function() {
		$('div.firmpage-msg div').each(function(i) {
			var object = this;
			
			setTimeout(function() {
				$(object).animate(
					{ borderTopColor: '#000000',
						borderLeftColor: '#000000',
						borderBottomColor: '#000000',
						borderRightColor: '#000000',
						backgroundColor: '#fafafa',
						color: '#404040' },
					2000
				);
			},(i * 5500));
		
			setTimeout(function() {
				$(object).fadeOut('slow');
			},((i * 5500) + 2000));

		});
	},3000);
*/
});

