/*
 * Threeformed Framework JS - http://www.threeformed.com/
 *
 * Copyright (c) 2007 Threeformed Media
 */
var included_files = new Array();var js_files = new Array();var class_obj;
$(document).ready(function() {
	//	find all elements that has 'attach' defined, then create a new class and bind it to the element
	$('.attach').each(function() {
		class_obj = $(this).attr('id');
		include_js("Scripts/Components/" + class_obj + "Component.js");
		var obj = eval('new ' + class_obj);
		$.extend(this, obj);
		$.extend(jQuery, obj);
	})
});

/**
 * Recursively searches under the form specified for the class, and adds the 
 * form elements name and value to the post_values class variable. 
 * 
 * @param none, except it does use the class variable "form_post" to find the form.
 */
function postForm(id) { 
	var form_control;
	//Access the form through the form_post name, or return.
	if($("#" + id).attr('id') != id) {
		return;
	}
	//Serialize the form, and add it to the post_values array.	
	list = $("#" + id).serialize();
	return list;
}

function handleResponse(js_content) {
	if (js_content.substr(0, 9) == '<!DOCTYPE') {
		return false;
	} else {
		if(window.execScript) {
			window.execScript(js_content);
		}else {
			if($.browser.safari){js_content = js_content.replace('function '+class_obj+'()', class_obj+' = function()');}
			window.eval(js_content);	
		}
		js_files[including_file] = true;
		return true;
	}
}

/**
 * This includes the javascript file passed to it.
 * 
 * @param {Object} file - Path to the file to include
 */
function include_js(file) {
	var myXMLHTTPRequest = null;
	js_files[file] = false;
	including_file = file;
	myXMLHTTPRequest = $.ajax({type: "GET", url: file, dataType: "script", async: false, success: handleResponse});
	return js_files[file];
}
