$(document).ready(function () {

    // load anchor into content area on page load
    var weblocation = 'http://www.ministryofgames.sg/games/';
	var hash = window.location.hash.substr(1);
	var toLoad = weblocation+hash+'.php';

	if (hash != '')
    {
        $('.games-list').load(toLoad);
        $(window).scrollTo('.games-h3', 1000);
        gamesCategory(hash);
    }

    // change image
    $(".games-category a").each(function(i) {
        var rel = $(this).attr('rel');
        if(hash == rel)
        {
            //alert(status);
            $(this).children('.img-default').hide();
            $(this).children('.img-active').show();
        }
	});

    /*$('.list .left img').livequery(function(){
        $(this).hover(function() {
            $(this).parent().next().find('.popup').fadeIn(220);
            $(this).css({'opacity' : '.7'});
        }, function() {
            $(this).css({'opacity' : '1'});
            $(this).parent().next().find('.popup').fadeOut(220);
        });
    }, function() {
        $(this)
            .unbind('mouseover')
            .unbind('mouseout');
    });*/

    $('.list .left img.thumb').livequery(function(){
        $(this).hover(function() {
        	$(this).next().show();
        }, function() {
        });
    }, function() {
        $(this)
            .unbind('mouseover')
            .unbind('mouseout');
    });

    $('.list .left img.popup').livequery(function(){
        $(this).hover(function() {
        }, function() {
    	    $(this).hide();
        });
    }, function() {
        $(this)
            .unbind('mouseover')
            .unbind('mouseout');
    });

    /*$(".list .left img.thumb").hover(function() {
        $(this).next().css({'z-index' : '1000'});
    	$(this).next().show();
    	$(this).next()
    		.css({
    			width: '252px',
    			height: '191px',
    			border: '10px solid #dc1607'
    		});

    	} , function() {
    });

    $(".list .left img.popup").hover(function() {

    	} , function() {
    	$(this).hide();
    });*/

    $('.games-category a').click(function(){
        var category = $(this).attr('href');
		var str = category.substring(1);
        $(this).children('.img-default').hide();
        $(this).children('.img-active').show();
        $(this).parent().siblings().find('a').children('.img-default').show();
        $(this).parent().siblings().find('a').children('.img-active').hide();
        var clicktoload = weblocation+str+'.php';
        $('.games-list').fadeOut(10);
        $('.games-loading-msg').show(10);
        $('.games-list').load(clicktoload, function() {
            gamesCategory(str);
            $('.games-loading-msg').hide();
            $('.games-list').fadeIn('slow');
            $(window).scrollTo('.games-h3', 500);
        });
        //alert(clicktoload);
	});

});

function gamesCategory(i){
    var textToLoad = "Featured";
    if(i == "colours-n-shapes"){
        var textToLoad = "Colours And Shapes";
    }
    else if(i == "brainteaser"){
        var textToLoad = "Brainteaser";
    }
    else if(i == "motor-skill"){
        var textToLoad = "Motor Skill";
    }
    else if(i == "communication"){
        var textToLoad = "Communication";
    }
    else if(i == "assortment"){
        var textToLoad = "Assortment";
    }
    else if(i == "adult-treat"){
        var textToLoad = "Adult Treat";
    }
    $('.games-h3').text(textToLoad);
}
