/* Menu Specific */

var menu = null;

function showMenu( _levelId, _elId ) {
	var thisLevel = document.getElementById( _levelId );
	var thisEl = _elId;
	if ( thisLevel.style.display == "none") {
		thisLevel.style.display = "block";
		state = "block";
		thisEl.className = 'menuHeader block';
	}
	else {
		thisLevel.style.display = "none";
		thisEl.className = 'menuHeader none';
		state = "none"
	}
	if (menu != null && menu.readyState != 0 && menu.readyState != 4) {
		menu.abort();
	}
	menu = AJAX();
	menu.open("GET", "/admincp/admin/remotemenusettings?name=" + _levelId + "&state=" + state);
	menu.send(null);
}

(function($) {
		  
	$.fn.imageRadios = function(options) {
		
		var imgHtml = '<img src="http://images.key2luxury.com/_library/{image}" title="{title}" alt="{title}" width="70" height="70">';
		
		var el = this.parent().get(0);
		
		if (typeof el != "undefined") {
			var data = $.data(el,'imageRadios');
			if (data == null)
				$.data(el,'imageRadios',this.parent().html()); //id/el, name, val
			else  {
				if (options != null) {
					this.parent().empty().html(data);
					$.removeData(el,'imageRadios');
					return this;
				}
			}
		}
		
		return this.each(function() {
			var self = this;
			var image = $('input',self).attr('id');
			var title = $(self).text();
			var html = imgHtml.replace(/\{image\}/,image).replace(/\{title\}/,title);
			var radio = $('input',self).get(0);
			$(self).hide().before(html);
			if (radio.checked==true)
				$(self).prev().addClass('selected');
		
			$(self).prev().click(function() { 
				$(this).parent().children('img').removeClass('selected');
				$(this).addClass('selected');
				radio.checked=true;
			});
		});
	};
	
	$(function() {
		
		$('table.list tbody tr:even').addClass('even');	
			   
		$('table.list tbody tr').hover(function(){
			this.style.cursor="pointer";
			this.style.backgroundColor='#FFFFCC';
		},function(){
			this.style.backgroundColor='';
		}).click(function(){
			elements = this.getElementsByTagName('a');
			if (elements.length!=0)
				document.location=elements[0].getAttribute('href');
		});
	});
})(jQuery)

// XMLHttpRequest function to initiate request object
function AJAX() {		
	var o = false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
 		try {
  			o = new ActiveXObject("Msxml2.XMLHTTP");
 		} catch (e) {
  			try {
   				o = new ActiveXObject("Microsoft.XMLHTTP");
  			} catch (E) {
   				o = false;
  			}
 		}
	@end @*/
	if (!o && typeof XMLHttpRequest!='undefined') {
		o = new XMLHttpRequest();
	}
	
	return o;
}

function openWin(loc,name,width,height,scrollbars) {
	var sY = (screen.height - height) / 2 ; var sX = (screen.width - width) / 2;
	popupWin = window.open(loc,name,'scrollbars='+scrollbars+',top='+sY+',left='+sX+',height='+height+',width='+width+'');
	popupWin.focus();
}

