/* default.js
--------
Copyright © 2008 Joris Landman. All rights reserved. http://jorislandman/ */

/* COOKIES
---------------- */
function joris_set_cookie(myname, myvalue, myexpiredays, mypath) {
	var myexpirationdate = new Date();
	myexpirationdate.setDate(myexpirationdate.getDate() + myexpiredays);
	document.cookie = myname + "=" +escape(myvalue) + ((myexpiredays == null) ? "" : ";expires=" + myexpirationdate.toGMTString() + ";path=" + mypath + ";");
}

/* UTILITIES
---------------- */
function joris_get_object(myobjectname) { // return cross browser object
	if (document.getElementById) {
		this.object = document.getElementById(myobjectname);
		this.style = document.getElementById(myobjectname).style;
	} else if (document.all) {
		this.object = document.all[myobjectname];
		this.style = document.all[myobjectname].style;
	} else if (document.layers) {
		this.object = document.layers[myobjectname];
		this.style = document.layers[myobjectname];
	} else {
		return false;
	}
}

function joris_mouse_coordinates(myevent) {
	// set up
	myevent = myevent || window.event;
	// return cross browser mouse coordinates
	if (myevent.pageX || myevent.pageY) {
		return {x: myevent.pageX, y: myevent.pageY};
	} else if (myevent.clientX || myevent.clientY) {
		return {x: myevent.clientX + document.body.scrollLeft - document.body.clientLeft, y: myevent.clientY + document.body.scrollTop - document.body.clientTop};
	} else {
		return false;
	}
}
function joris_get_mouse_coordinates(myevent) {
	// set up
	myevent = myevent || window.event;
	// get mouse coordinates
	var mymousecoordinates = joris_mouse_coordinates(myevent);
	return mymousecoordinates;
}

function joris_element_coordinates(myobject) {
	// set up
	var myx = 0;
	var myy = 0;
	// return element coordinates
	if (myobject.offsetParent) {
		// recursive check for parents' coordinates
		do {
			myx += myobject.offsetLeft;
			myy += myobject.offsetTop;
		}
		while (myobject = myobject.offsetParent);
		return {x: myx, y: myy};
	}
}
function joris_get_element_coordinates(myobject) {
	// set up
	var myelementcoordinates = new joris_element_coordinates(myobject);
	// get element coordinates
	return myelementcoordinates;
}

function joris_element_dimensions(myobject) {
	// set up
	var mywidth = myobject.offsetWidth;
	var myheight = myobject.offsetHeight;
	// return element dimensions
	return {x: mywidth, y: myheight};
}
function joris_get_element_dimensions(myobject) {
	// set up
	var myelementdimensions = new joris_element_dimensions(myobject);
	// get element dimensions
	return myelementdimensions;
}

function joris_window_dimensions() {
	// set up
	var mywidth = 0;
	var myheight = 0;
	if(typeof(window.innerWidth) == 'number') {
		// non IE
		mywidth = window.innerWidth;
		myheight = window.innerHeight;
	} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		// IE6+ standards compliant mode
		mywidth = document.documentElement.clientWidth;
		myheight = document.documentElement.clientHeight;
	} else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
		// IE4
		mywidth = document.body.clientWidth;
		myheight = document.body.clientHeight;
	}
	// return element dimensions
	return {x: mywidth, y: myheight};
}
function joris_get_window_dimensions() {
	// set up
	var mywindowdimensions = new joris_window_dimensions();
	// get window dimensions
	return mywindowdimensions;
}

function joris_document_dimensions() {
	// set up
	var mywidth = 0;
	var myheight = 0;
	mywidth = document.body.clientWidth;
	myheight = document.body.clientHeight;
	// return element dimensions
	return {x: mywidth, y: myheight};
}
function joris_get_document_dimensions() {
	// set up
	var mydocumentdimensions = new joris_document_dimensions();
	// get document dimensions
	return mydocumentdimensions;
}

/* CHANGE OBJECT PROPERTIES
---------------- */
function joris_change_object_property(myobjectname, myproperty, mynewvalue) {
	var myobject = new joris_get_object(myobjectname);
	myobject.object[myproperty] = mynewvalue;
}

function joris_change_style_property(myobjectname, myproperty, mynewvalue) {
	var myobject = new joris_get_object(myobjectname);
	myobject.style[myproperty] = mynewvalue;
}

