
// append system data to the page
$(document).ready(function(){

	//Template for Confirm message
	var comfirmTpl = "" +
		"<div id='idConfirmBox' style='display:none;'>" +
			"<a href='#' title='Close' class='modalCloseX simplemodal-close'>x</a>" +
			"<div class='header'><span>Confirm</span></div>" +
			"<p class='message'></p>" +
			"<div class='buttons'>" +
				"<div class='no simplemodal-close'>No</div><div class='yes'>Yes</div>" +
			"</div>" +
		"</div>";
	$("body").append(comfirmTpl);
	
	//Template for Alert Message
	var alertTpl = ""+
		"<div id='idAlertBox' style='display:none;'>"+
		"<table>"+
		"<tr>"+
			"<td width='48'><img src='img/lisk/alert.png'/></td>"+
			"<td>"+
				"<ul style='padding:3px 3px 3px 12px;margin:0px;' id='idAlertItems'>"+
					"<li></li>"+
				"</ul>"+
			"</td>"+
		"</tr>"+
		"</table>"+
		"</div>";	
	$("body").append(alertTpl);

	//Template for Notify Message
	var notifyTpl = ""+
		"<div id='idNotifyBox' style='display:none;'>"+
		"<table>"+
		"<tr>"+
			"<td width='48'><img src='img/lisk/success.gif'/></td>"+
			"<td>"+
				"<ul style='padding:3px 3px 3px 14px;margin:0px;' id='idNotifyItems'>"+
					"<li></li>"+
				"</ul>"+
			"</td>"+
		"</tr>"+
		"</table>"+
		"</div>";	
	$("body").append(notifyTpl);
	
	//zoom, ie6 throws exception
	try
	{
		$("a[liskZoom=true]").fancybox({hideOnContentClick:true});
	}
	catch (ex) {  }
	
	//fix pngs for ie6
	if (jQuery.ifixpng) jQuery.ifixpng.pixel = 'img/0.gif';
	
	// Remove background of last top menu item because IE does not support last-child selector
	$("div.top-menu ul li:last-child a").css("background","none");
});

function ShowConfirm(message, callback) 
{
	$('#idConfirmBox').modal({
		close:true, 
		position: ["25%"],
		overlayId:'confirmModalOverlay',
		containerId:'confirmModalContainer', 
		onShow: function (dialog) {
			dialog.data.find('.message').append(message);
			dialog.data.find('.yes').click(function () {
				$.modal.close();
				
				//check callback
				if (eval("(typeof(callback) != 'function') && (typeof(callback) != 'object')")) return false;

				//link
				if (callback.href)
				{
					location.href = callback.href;
					return true;
				}

				//form
				if(1==1)
				{

				}

				//function
				if ($.isFunction(callback)) 
				{
					callback.apply();
				}
			});
		}
	});
	$('#confirmModalContainer').draggable();

	return false;
}


function ShowAlert(message, type)
{
	if (!type) type='error';
	
	var blockId = 'idAlertBox';
	var itemsId = 'idAlertItems';
	if (type=='notify') 
	{
		blockId = 'idNotifyBox';
		itemsId = 'idNotifyItems';
	}
	
	$('#'+blockId).modal({
		position: ["25%"],
		onShow: function (dialog) {
			if (message.push) //array of messages
			{
				var messages = '';
				for (var i=0; i<message.length; i++) messages += "<li>"+message[i]+"</li>";
				dialog.data.find('#'+itemsId).html(messages);
			}
			else dialog.data.find('#'+itemsId).html("<li>"+message+"</li>"); //single message
		}
	});
	$('#simplemodal-container').draggable();
	
	//pngfix still not 100% working
	try
	{
		$("#idAlertBox img").ifixpng(); 
		$("a.modalCloseImg").ifixpng(); 
	}
	catch (ex) { }
}

function popupWindow(url,width,height,scroll) 
{
	var popUpWin = 0;
	
	if (scroll==null) scroll=false;
	
	if(popUpWin) if(!popUpWin.closed) popUpWin.close();

	var left = (screen.width/2) - width/2;
  	var top = (screen.height/2) - height/2;
  	var scrolling = (scroll) ? 'yes' : 'no';

	popUpWin = open(url, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scrolling+',resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top);
	popUpWin.focus();
}

function alertObj(obj, showValues)
{
	showValues = (showValues) ? true : false;
	var buf = '';
	for (var prop in obj)
	{
		if (showValues) buf += ' ' + prop + '=' + obj[prop] + ', ';
		else buf += ' ' + prop + ' ';
	}
	alert(buf);
}


(function($) {
	/**
	 * equalizes the heights of all elements in a jQuery collection
	 * thanks to John Resig for optimizing this!
	 * usage: $("#col1, #col2, #col3").equalizeCols();
	 */
	 
	$.fn.equalizeCols = function(){
		var height = 0,
			reset = $.browser.msie ? "1%" : "auto";
  
		return this
			.css("height", reset)
			.each(function() {
				height = Math.max(height, this.offsetHeight);
			})
			.css("height", height)
			.each(function() {
				var h = this.offsetHeight;
				if (h > height) {
					$(this).css("height", height - (h - height));
				};
			});
			
	};
	
})(jQuery);

/* fix blue cubes for ie6 */
$(function(){
	if ($.browser.msie && $.browser.version==6)
	{
		var isServicesPage = location.pathname.match('our_services/');
		var isViewGroupPage = location.pathname.match('our_services/view_group/');
		
		$cube = $('<img src="img/blue_cube.gif" class="cube" />');
		
		if (isServicesPage && (!isViewGroupPage)) $cube.css({top:'8px'});
			
		$('ul.blue li, ul li.blue').css({position: 'relative'}).prepend($cube);
	}
})