(function(){
    $.fn.contact_form = function() {
    	$(this).click(function() { 
    		$('#cnt-frm').dialog('open');
    		return false;
    	});
    	$('#cnt-frm').dialog({
			autoOpen: false, draggable: false, resizable: false,
			height: 550, width: 632, modal: true, dialogClass: 'ui-cnt-frm',
			buttons: {},
			open: function() {
				$('.ui-cnt-frm,.ui-cnt-frm .ui-dialog-content').css({'background': 'none', 'border': '0', 'padding': '0' });
				$('.cnt-frm-cls').click(function(){ $('#cnt-frm').dialog('close'); return false; });
			},
			close: function() {	}
		});    	
    };
	
	$.fn.banner_logo = function() {
		$(this).hide(); window.setTimeout(function(){ $('#cmn-bnr-log-con').fadeIn(2000); }, 1500); 
	};
	
	$.fn.side_slides = function() { var sld=$(this); var tot = $('.sid-log-sld-itm', sld).size(); var prev = 1; 
		$('.sid-log-sld-itm', sld).hide(); $('.sid-log-sld-itm:nth-child(0)', sld).show();
		window.setInterval(function(){ showNext(); }, 4000); 
		function showNext() { var cur = prev+1; if (cur > tot) cur = 1;
			$('.sid-log-sld-itm:nth-child('+prev+')', sld).hide();
			var el = $('.sid-log-sld-itm:nth-child('+cur+')', sld).show(); $('img', el).hide().fadeIn(2000); prev = cur;
		}
		showNext();
	};
	
	$.fn.matrixbox = function() { 
		$(this).click(function() { $('.mbox').dialog('open'); return false; }); var box=$('.mbox');
		
		box.html('<div class="mbox-wrp-top"><div class="mbox-cls"></div></div><div class="mbox-wrp-con">'+box.html()+'</div><div class="mbox-wrp-bot"></div>');
    	box.dialog({
			autoOpen: false, draggable: false, resizable: false,
			height: 570, width: 632, modal: true, dialogClass: 'ui-cnt-frm',
			buttons: {},
			open: function() {				
				$('.mbox-cls').click(function(){ $('.mbox').dialog('close'); return false; });
				$('.mbox-tip').mtip();
			},
			close: function() {	}
		});    			
	};
	
	$.fn.mtip = function() { var xOffset = 20; var yOffset = -10;
		$(this).each(function() { var el = $(this); 
			if (!el.data('tip')) 
			{
				el.data('tip', el.html()); el.html('<div class="mbox-tip-con">&nbsp;</div>');
				$('.mbox-tip-con',el).css({ 'height':el.height()+'px', 'width':el.width()+'px'});
			}
			$('.mbox-tip-con',el).unbind().hover(function(e) {				
				$('p#mtip').remove();
				$('body').append('<p id="mtip"><span id="mtip-arr">&nbsp;</span><span>' + $(this).parent().data('tip') + '</span></p>');				
				$("p#mtip").css("top", (e.pageY + yOffset)+"px").css("left", (e.pageX + xOffset)+"px").fadeIn("fast");
			}, function() {
				$("p#mtip").fadeOut("fast").remove();
			}).mousemove(function(e) {
				this.top = (e.pageY + yOffset);
				this.left = (e.pageX + xOffset);                         
				$("p#mtip").css("top", (e.pageY + yOffset)+"px").css("left", (e.pageX + xOffset)+"px");
			});			
		});	
	};

})(jQuery);

$(document).ready(function() {	
	$('#cmn-hdr-mnu-amd').contact_form(); $('#cmn-bnr-log-con').banner_logo(); $('#sid-log-sld').side_slides();
	$('#mlnk').matrixbox(); $('.sid-ban-frm').click(function() { $('.thumpWnd,#mlnk', $(this).parent()).click(); return false; });
});
