var jq = jQuery.noConflict();

jq(document).ready(function ()
	{
		// Start fixed menu
		jq("div.menu > a").hide();

		jq("div.menu").hover(function()
			{
				jq(this).children('a').slideDown('normal');
			},
			function(){
				jq(this).children('a').slideUp('normal');
			});
		// End fixed menu

		// Start modal dialog
		//select all the a tag with name equal to modal
		jq('a[name=modal]').click(function(e) {
			//Cancel the link behavior
			e.preventDefault();
			//Get the A tag
			var id = jq(this).attr('href');

			//Get the screen height and width
			var maskHeight = jq(document).height();
			var maskWidth = jq(window).width();

			//Set height and width to mask to fill up the whole screen
			jq('#mask').css({'width':maskWidth,'height':maskHeight+10});

			//transition effect
			jq('#mask').fadeIn(1000);
			jq('#mask').fadeTo("slow",0.8);

			//Get the window height and width
			var winH = jq(window).height();
			var winW = jq(window).width();

			//Set the popup window to center
			jq(id).css('top',  winH/2-jq(id).height()/2);
			jq(id).css('left', winW/2-jq(id).width()/2);

			//transition effect
			jq(id).fadeIn(2000);

		});

		//if close button is clicked
		jq('.window .close').click(function (e) {
			//Cancel the link behavior
			e.preventDefault();
			jq('#mask, .window').hide('normal');
		});

		//if mask is clicked
		jq('#mask').click(function () {
			jq('.window').hide('fast');
			jq(this).hide('normal');
		});
		// End modal dialog
		
		// Start clear input value script
		jq("input[rel='user']").click(function(){
				if (jq(this).val()=='Username'){
					jq(this).val("");
				}
		});
		
		jq("input[rel='pass']").click(function(){
				if (jq(this).val()=='Password'){
					jq(this).val("");
					this.type="password";
				}
		});
		// End clear input value script
		
		// Start Login
		
		jq("#login_form").submit(function(e) {
			//Cancel the link behavior
			e.preventDefault();
			
			user = jq("[rel='user']").val();
			pass = jq("[rel='pass']").val();
			
			jq.ajax({url:'login.php', data:'user='+user+'&pass='+pass, context: document.body, cache:false, success:function(data){
				jq("#login").children().fadeOut(1000, function(){
					jq("#login").append("<div id='data'>"+data+"</div>");
				
					})}
						
				});
			});
		
		jq("#showLogin").click(function(e){e.preventDefault();jq("#login").children().fadeIn(1000, function(){jq("#data").hide()})});
		
		// End Login
	});

// Start collapse buttons
function toggle(name)
	{
		jq("[name="+name+"]").toggle("slow");
	}
// End collapse buttons

// Start showChildren
function showChildren(select)
	{
	jq(select).children().fadeIn(1000);
	}
// End showChildren
