$(document).ready(function(){

	$("#wigo_logo").click(function(){
		window.location = "index.php";
	});

	/* For Menu Hover Style */
	$("a.topMenu").hover(
		function(){
			$(this).stop().animate({
				color: '#ACDCF7'
			}, 200);
		}, 
		function(){
			$(this).stop().animate({
				color: '#0066CC'
			}, 200);
		}
	);
	/* End For Menu Hover Style */

	/* For Channel Hover Style */
	$(".channelQuote").hover(
		function(){
			$(this).stop().animate({
				backgroundColor: '#ffffff'
			}, 400);
		}, 
		function(){
			$(this).stop().animate({
				backgroundColor: '#66CCCC'
			}, 400);
		}
	);
	/* End For Channel Hover Style */

	/* For Curved Corners */
	$("#topMenu").each(function(){
		$(this).append("<p class='hidden'>$(this).corner('round');</p>");
		eval($('p.hidden', this).text());
	});

	$("#poll").each(function(){
		$(this).append("<p class='hidden'>$(this).corner();</p>");
		eval($('p.hidden', this).text());
	});

	$("#communityTalk").wrap('<div class="outer" style="background-color:#DAE6F4"></div>');
	$("#communityTalk").each(function(){
		$(this).append("<p class='hidden'>$(this).corner('round').parent().css({'padding':'2px','margin':'7px 0 0 5px'}).corner('round');</p>");
		eval($('p.hidden', this).text());
	});

	$('.points').wrap('<div class="outer" style="background-color:#F7D9EC;"></div>');
	$(".points").each(function(){
		$(this).append("<p class='hidden'>$(this).corner('round').parent().css({'padding':'6px','margin-left':'20px'}).corner('round');</p>");
		eval($('p.hidden', this).text());
	});

	$('.box').wrap('<div class="outer" style="background-color:#E5F8FE;"></div>');
	$(".box").each(function(){
		$(this).append("<p class='hidden'>$(this).corner('round').parent().css({'padding':'1px'}).corner('round');</p>");
		eval($('p.hidden', this).text());
	});

	$('.classified').wrap('<div class="outer" style="background-color:#734dff;"></div>');
	$(".classified").each(function(){
		$(this).append("<p class='hidden'>$(this).corner('round 20px').parent().css({'padding':'3px'}).corner('round 20px');</p>");
		eval($('p.hidden', this).text());
	});

	$('#login').wrap('<div class="outer" style="background-color:#649AFE;"></div>');
	$("#login").each(function(){
		$(this).append("<p class='hidden'>$(this).css({'overflow':'hidden'}).corner('round 30px').parent().css({'padding':'10px'}).corner('round 30px');</p>");
		eval($('p.hidden', this).text());
	});

	$('#reminder').wrap('<div class="outer" style="background-color:#649AFE;"></div>');
	$("#reminder").each(function(){
		$(this).append("<p class='hidden'>$(this).corner('round 30px').parent().css({'padding':'10px'}).corner('round 30px');</p>");
		eval($('p.hidden', this).text());
	});
	/* End For Curved Corners */

	// Search by category - For Grabs
	$('#mainCategory').change(function(){
		var mainCategory = $("option:selected", this).val();

		$('#subCategory').hide();
		if(mainCategory != 0){
			// do ajax
			dataStr	= 'category=' + mainCategory;

			$.ajax({
				url		: 'programs/selectCategory.php',
				data	: dataStr,
				type	: 'post',
				success	: function(g){
					$('#category').html(g);
				}
			}); // End of $.ajax

			$('#subCategory').show();	// show sub-categories

			// submit search sub-category
			$('#categoryForm').submit(function(g){
				g.preventDefault();
				var category	= $("option:selected", this).val();
				var pagename	= $('#pagename').val();
				var msg			= "";

				if(category == 0){
					msg+= "Please Select Sub-category.";
				}

				if(msg){
					alert(msg);
					return false;
				}
				else{
					window.location = "index.php?pagename="+pagename+"&maincategory="+mainCategory+"&category="+category+"";
				}
			}); // End submit categoryForm
		}
	});
	// End Search by category - For Grabs

	if($.browser.msie){ // If browser is IE. Insert the css fix for Login in IE
		$('div#loginDiv').css({'margin':'0','padding':'0','overflow':'hidden'});
	}

	// For Modal Windows
	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(g) {
		//Cancel the link behavior
		g.preventDefault();
					
		//Get the A tag
		var id = $(this).attr('href');
		var type = "login";

		showWindow(id,type);
				
	});

	$('a[name=modalreg]').click(function(g){
		g.preventDefault();

		var id = $(this).attr('href');
		var type = "reg";

		showWindow(id,type);

	});
				
	//if close button is clicked
	$('.close').click(function (g) {
		//Cancel the link behavior
		g.preventDefault();

		$('#mask').hide();
		$('.window').hide();
		/*parent.location.reload();*/
		/* this will refresh the page */
		top.location = 'http://www.wigo.ph/'; // dont forget to change this in production.
	});

	// Close the window only
	$('.closeWindow').click(function(g){
		g.preventDefault();

		$('#mask').hide();
		$('.window').hide();
	});
	
	// End For Modal Windows

});
				
function showWindow(id,type){

	//Get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();
				
	//Set heigth and width to mask to fill up the whole screen
	$('#mask').css({'width':maskWidth,'height':maskHeight});
					
	//transition effect		
	$('#mask').fadeIn(500);	
	$('#mask').fadeTo("slow",0.5);	
				
	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();

	//Set the popup window to center
	if(type == 'login'){
		/*$(id).css('position','fixed'); */ // to make the window alwas at the center of the screen.
		$(id).css('top',  winH/2-$(id).height()/2); 
		$(id).css('left', winW/2-$(id).width()/2);
	}
	else{
		$(id).css('top','50px');
		$(id).css('left', winW/2-$(id).width()/2);
	}
		
	//transition effect
	$(id).fadeIn(500); 
				
}

function showHideDiv(id,fnc,divID,divValue){
	var	id	= id;
	var fnc	= fnc;
	var divID	= divID;
	var divValue	= document.getElementById(divID).innerHTML;
			

	if(divValue == 'Change'){
		document.getElementById(divID).innerHTML	= 'hide';
		document.getElementById(id).style.display	= '';
	}
	else{
		document.getElementById(divID).innerHTML	= 'Change';
		document.getElementById(id).style.display	= 'none';
	}
}

