var arr_onload = Array();
if (typeof($) == 'function') {
	$(document).ready(function(){
		$('img.img_modal').each(function(){
			var $img = $(this);
			var img_temp = new Image();
			img_temp.onload = function(){
				var int_w = img_temp.width;
				var int_h = img_temp.height;
				$img.css('cursor',(int_ie_ver == 6) ? 'hand' : 'pointer');
				$img.click(function(){
					arr_dim = SS_ScaleTo([int_w,int_h],[$(window).width() - 20,$(window).height() - 20]);
					var $img_new = $(img_temp);
					$img_new
					.css({
						'display':'none',
						'width':arr_dim[0] + 'px',
						'height':arr_dim[1] + 'px',
						'cursor':(int_ie_ver == 6) ? 'hand' : 'pointer'
					})
					.click(function(){
						$.modal.close();
					});
					$('body').append($img_new);
					$img_new.modal({overlayCss:{'background-color':'#000','cursor':'wait'}});
				});
			};
			img_temp.src = this.src;
		});
	});
}
window.onload = function() {
	for (var i=0;i<arr_onload.length;i++) {
		arr_onload[i]();
	}
}

function SS_ScaleTo(arr_src,arr_max) {
	var int_new_w = arr_src[0];
	var int_new_h = arr_src[1];
	if (arr_src[0] > arr_max[0] || arr_src[1] > arr_max[1]) {
		if (arr_src[0] / arr_src[1] > arr_max[0] / arr_max[1]) {
			int_new_w = arr_max[0];
			int_new_h = parseInt(int_new_w / arr_src[0] * arr_src[1]);
		} else {
			int_new_h = arr_max[1];
			int_new_w = parseInt(int_new_h / arr_src[1] * arr_src[0]);
		}
	}
	return [int_new_w,int_new_h];
}

function SS_JoinEmail(str_link_id, str_domain,str_user) {
	var str_email_addr = str_user + String.fromCharCode(Math.pow(2,6)) + str_domain;
	var obj_link = document.getElementById(str_link_id);
	obj_link.href = 'mail' + 'to:' + str_email_addr;
	obj_link.innerHTML = str_email_addr;
}
function SS_Popup(str_url) {
	MM_openBrWindow(str_url,'','scrollbars=yes,width=420,height=420');
	return false;
}
function SS_HttpReq(str_http_url, obj_function) {
	if (typeof(SS_AjaxStart) == 'function') SS_AjaxStart();
	var xmlHttpReq = false;
	var self = this;
	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq.open('GET', str_http_url, true);
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
			if (typeof(SS_AjaxComplete) == 'function') SS_AjaxComplete();
			if (self.xmlHttpReq.status==200) {
				if (typeof(obj_function) == 'function') obj_function(self.xmlHttpReq.responseText);
			} else {
				alert('HTTP Error ' + self.xmlHttpReq.status + ' occured while getting content.');
			}
		}
	}
	self.xmlHttpReq.send(null);
}
function SS_UrlEncode(str_input) {
	return escape(str_input).replace(/\+/g,'%2B');
}
function SS_HTMLEncode(str_input) {
   var obj_div = document.createElement('div');
   var obj_text = document.createTextNode(str_input);
   obj_div.appendChild(obj_text);
   return obj_div.innerHTML;
}
function MM_goToURL() {
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}
