// JavaScript Document

var _mainRoot = '/games/';

$(function(){
    $("ul.dropdown li").hover(function(){
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    }, function(){
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    });
    $("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");
	$("ul.dropdown ul").find("li:last").css("border-bottom","1px solid #ccc");
});

$(document).ready(function(){       
	$("#show_morecats").click(function(){
		$("#morecats").slideToggle("slow", function() { 
			$("#show_morecats").toggleClass("jq_selected");
        });
	});
	
	//top search box
    $("#top_search").focus(function(){
        //for brain games
		if ($.trim($("#top_search").val())=='Search Brain Games'){
            $("#top_search").val('');
        }
		
		//for sliding puzzle
		if ($.trim($("#top_search").val())=='Search Sliding Puzzles'){
            $("#top_search").val('');
        }
		
		//for jigsaw puzzle
		if ($.trim($("#top_search").val())=='Search Jigsaw Puzzles'){
            $("#top_search").val('');
        }
		
		//for word search
		if ($.trim($("#top_search").val())=='Search Word Search'){
            $("#top_search").val('');
        }
		
		//for word search
		if ($.trim($("#top_search").val())=='Search Brain Teasers'){
            $("#top_search").val('');
        }
		
		//for crossword puzzle
		if ($.trim($("#top_search").val())=='Search Crossword Games'){
            $("#top_search").val('');
        }
		
		//for hangman game
		if ($.trim($("#top_search").val())=='Search Hangman Games'){
            $("#top_search").val('');
        }
		
		//for word scramble game
		if ($.trim($("#top_search").val())=='Search Word Scramble Games'){
            $("#top_search").val('');
        }
		
		//for word scramble game
		if ($.trim($("#top_search").val())=='Search Brain Teasers'){
            $("#top_search").val('');
        }
    });
	
	if($("#searchfilter input[type=radio]").length>0){
		$("#searchfilter input[type=radio]").click(function(){
			var _top_s = $(this).attr("value");
			$("#top_searchForm").attr("action", _top_s);
			
			if(_top_s == '/games/word-search/s/'){
				$("#top_search").attr("value", "Search Word Search");
			}else if(_top_s == '/games/puzzle/sliding/s/'){
				$("#top_search").attr("value", "Search Sliding Puzzles");
			}else if(_top_s == '/games/jigsaw/s/'){
				$("#top_search").attr("value", "Search Jigsaw Puzzles");
			}else if(_top_s == '/games/brain-teasers/s/'){
				$("#top_search").attr("value", "Search Brain Teasers");
			}else if(_top_s == '/games/crossword/s/'){
				$("#top_search").attr("value", "Search Crossword Games");	
			}else if(_top_s == '/games/word-games/hangman/s/'){
				$("#top_search").attr("value", "Search Hangman Games");	
			}else if(_top_s == '/games/word-games/word-scramble/s/'){
				$("#top_search").attr("value", "Search Word Scramble Games");	
			}else if(_top_s == '/games/brain-teasers/s/'){
				$("#top_search").attr("value", "Search Brain Teasers");	
			}else if(_top_s == '/games/s/'){
				$("#top_search").attr("value", "Search Brain Games");	
			}else{
				$("#top_search").attr("value", "Search Brain Games");		
			}
		});
	}
});


// JavaScript Document
function validateEmail(email){
	if (email != '' && !/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(email)){ return false;	}
	return true;
}

function validateUrl(url){
	if (url != '' && !/^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(url)){ return false;	}
	return true;
}