$(document).ready(function(){
        $('#removeme').click(function(){
           var myemail = $('#email').val();
           var eg = /.+@.+\..+/;

           if (!myemail.match(eg)){
               $('#errorme').text('Invalid email address entered.')
               return false;
           }

        });

	$("#sitemap").treeview({
		persist: "location",
		collapsed: true,
		unique: true
	});
        $("#skipvideo").livequery('click', function(){
            $(this).hide();
            $("#abouttext").show();
            $("#aboutvideo").hide();
            return false
        });

//cycle images in news page
        $('#banner-news')
        .livequery(function(){
            $(this).cycle('fade');
        });

//validate form

        $('#myForm')
          .livequery(function(){

              $(this).validate();

          });
        
//in casino page
        $('#banner-casino')
        .livequery(function(){
            $(this).cycle('fade');
        });

//watermark
        $("#insic").Watermark("Site Search");
        $("#ca-username")
            .livequery(function(){
                $(this).Watermark("Username");
            });

        $("#ca-password")
            .livequery(function(){
                $(this).Watermark("********");
            });
//rounded corner

        $(".activesub")
        .livequery(function(){
            $(this).corner('5px');
        });

//        $(".homepage-gt")
//        .livequery(function(){
//            $(this).corner('10px');
//        });
        $(".mc-curve")
        .livequery(function(){
            $(this).corner('10px');
        });

//accordion

        $(".accordion h5:first")
        .livequery(function(){
            $(this).addClass("active");
        });

        $(".accordion div.accordionchild:first")
        .livequery(function(){
            $(this).show();
        });

        $(".accordion h5")
        .livequery('click', function(){
                $(this).next("div.accordionchild").slideToggle("fast")
                .siblings("div:visible").slideUp("fast");
                $(this).toggleClass("active");
                $(this).siblings("h5").removeClass("active");
        });

//accordion2 archive

        $(".accordion2 h5:first")
        .livequery(function(){
            $(this).addClass("active");
        });

        $(".accordion2 h5")
        .livequery('click', function(){
                $('span.loading').remove();
                $(this).before('<span class="loading">&nbsp;</span>');
                $(this).next("div.accordionchild")
                .load('home/getarchivecontent/'+ $(this).attr('id')).slideToggle("fast")
                .siblings("div:visible").slideUp("fast");

                $(this).toggleClass("active");

                $(this).siblings("h5").removeClass("active");

               $('span.loading').fadeOut('slow');

        });


//flag tooltip
        $(".language a").hover(function() {
            $(this).next("em").animate({opacity: "show", top: "15"}, "slow");
        }, function() {
            $(this).next("em").animate({opacity: "hide", top: "25"}, "fast");
        });

// ajax page transition

	var hash = window.location.hash.substr(1);
	var href = $('#menu li a').each(function(){
		var href = $(this).attr('href');
		if(hash==href.substr(0,href.length)){
			var toLoad = hash+' #content';
			$('#content').load(toLoad)
            $('.news-box').remove()
		}
	});

//******************************************************************************
//Using livequery in submenu transition.
//******************************************************************************
$('#submenu li:contains(Sciplay)').livequery(function(){
    $(this).attr('id', 'redMenu');
});


$('#submenu li a').livequery('click', function(){
       
		var toLoad = $(this).attr('href')+' #content';
        var curPage = $(this).attr('href').substr(5, $(this).attr('href').length);

        $('#load').remove();

		$('#content').fadeOut('slow',loadContent);

		$('#wrapper').append('<span id="load">LOADING...</span>');

        $('#load').fadeIn('slow');



          if($.browser.msie){

            var test = $(this).attr('href').replace(/^.*page/, '#page');
           
            window.location.hash = test;

          }else{

window.location.hash = $(this).attr('href');
            
          }
        
		
        

        function loadContent() {

            //remove the content completely resolved the transition bug.
            $('#contents').remove();

            //load the content
			$('#content').load(toLoad,'',showNewContent());

		}

        function hideLoader() {

			$('#load').fadeOut('slow');

		}

		function showNewContent() {

			$('#content').fadeIn('slow',hideLoader());

		}
		return false;

	});

//******************************************************************************

      $('#menu li.external a').click(function(){
		window.location.href = $(this).attr(href);
	});

	$('#menu li a').click(function(){

		var toLoad = $(this).attr('href')+' #content';
        var curPage = $(this).attr('href').substr(11, $(this).attr('href').length);
        var curPageMenu = $(this).attr('href').substr(5, $(this).attr('href').length);

        $('#menuWrap').removeClass();

        $('#load').remove();

		$('#content').fadeOut('slow',loadContent);

        $('#menuWrap').addClass(curPageMenu+'Wrap');

		$('.news-box').remove();

		$('#wrapper').append('<span id="load">LOADING...</span>');

        $('#load').fadeIn('slow');

		window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length);

		function loadContent() {

            //remove the content completely resolved the transition bug.
            $('#contents').remove();

            //load the content
			$('#content').load(toLoad,'',showNewContent());

		}

        function hideLoader() {

			$('#load').fadeOut('slow');

		}

		function showNewContent() {

			$('#content').fadeIn('slow',hideLoader());

		}

		return false;

	});

});

        function hideVideo(){
            $("#abouttext").show();
            $("#aboutvideo").hide();
            return false
        }
