//Global Settings
var glSet = {};
//Download client link
glSet.dwnLink = 'http://banner.mansionpoker.com/cgi-bin/SetupPoker.exe';



$(document).ready(function(){

//	console.log('welcome to mansion', jQuery);

    //this is magic tables fix to make it fine and zebra
    fUI.tableZebra('table');

    //fix sidebar
    fUI.fixSB();


    //this is hover top and bottom menu
	$('#top-menu li, #bottom-menu li').hover(
		function(){
            if ($(this).hasClass('active')) return;
			else if($(this).hasClass('first')) $(this).css('background', 'transparent url(/sites/mansionpoker.com/themes/mansionp/styles/media/linksBGHoverLeft.gif) no-repeat top left');
			else if($(this).hasClass('last')) $(this).css('background', 'transparent url(/sites/mansionpoker.com/themes/mansionp/styles/media/linksBGHoverRight.gif) no-repeat top right');
			else $(this).css('background', 'transparent url(/sites/mansionpoker.com/themes/mansionp/styles/media/linksBGHover.gif)');
		},
		function(){
            if ($(this).hasClass('active')) return;
			$(this).css('background', 'none');
		}
	);

    //equal height fix for header
	fUI.eqH('#header-main > div');


    //language drop down menu
    $('#langbar').hover(
        function(){
            var _langCount = $('li', this).length;
            var _multyBy = 24;
            var _langH = _langCount*_multyBy;
            $(this).height(_langH);
        },
        function(){
            $(this).height(24);
        }
    );
    

    //current lang not clickable
    $('#langbar .current a').live('click', function(){
        return false;
    });

    //lang switch
	$('#langbar li:not(.current)', this).hover(
		function(){
			$(this).addClass('hover');
		},
		function(){
			$(this).removeClass('hover');
		}
	);


    //collapse pages define by classes
    //to add more collapse use this function. just add classes
    $('.faq-question, .col-exp').toggle(
        function(){
            $(this).siblings('div').fadeIn('fast');
            fUI.fixSB();
            
        },
        function(){
            $(this).siblings('div').fadeOut('fast');
            fUI.fixSB();
        }
    );


    //payments or deposit call it as you like
    //this will display payment method on icon click
    if( $('.payment-icon').length > 0 ){
        $('.payment-icon').live('click', function(){
            var pay_id = $(this).attr('rel');
            $('#'+pay_id).next().toggle().siblings('.expand').hide();
            window.location.hash = '#'+pay_id;
            fUI.fixSB();
            return false;
        });


        //activate download on click on download_button inside deposit options
        $('.download_button').live('click', function(){
            window.location.href = glSet.dwnLink;
            return false;
        });

    }



    //download page before and after h2
    if( $('#downloadpage').length > 0 ){

        //create image before
        var _before = new Image();
        //create image after
        var _after = new Image();
        
        _before.src = '/sites/mansionpoker.com/themes/mansionp/styles/media/downloadTitleLeft.gif';
        $(_before).addClass('heading_decor');
        _after.src = '/sites/mansionpoker.com/themes/mansionp/styles/media/downloadTitleRight.gif';
        $(_after).addClass('heading_decor');
        
        //console.log($(_before), $(_after));
        
        $('.top_content h2')
            .prepend( $(_before) )
            .append( $(_after) );


        //download trigger
        $('.donwn-items, .download_bottom')
            .hover(
                function(){
                    $(this).css('cursor', 'pointer');
                },
                function(){
                    $(this).css('cursor', 'default');
                }
            )
            .live('click', function(){
                window.location.href = glSet.dwnLink;
                return false;
            });

        $(window).load(function(){
            window.location.href = glSet.dwnLink;      
        });
        
    }


});





$(window).load(function(){
    //this should fix sidebar menu height
    fUI.fixSB();
});





//===============================================================
//===============================================================


//This is fUI class that make things.
//do not edit what already wrottern. extend or add your function
//note if you broke it you pay.

var fUI = {
	//this will make equal height for group of items
	eqH: function(group){
		var _group = group || null;
		if (_group != null) {
			var _items = $(''+_group+'');
			var _mH = 0;
			$.each(_items, function(){
				if ($(this).height() > _mH) _mH = $(this).height();
			});
			$(_items).height(_mH);
		}
	},

    //This will fix sidebar height
    fixSB: function(){
        this.cH = $('#content').height();
        $('#side-blocks').height(this.cH);
    },


    //This will make table zebra
    tableZebra: function(selector){
        this.tables = $(''+selector+'');
        if ( this.tables.length > 0 ){
            $.each(this.tables, function(i){
                var rows = $('tr', this);
                if( rows.length > 0 ){
                    $.each(rows, function(k){
                        if( k == 0 ) $(this).addClass('zthead');
                        else {
                            if(k % 2) $(this).addClass('tzebra_1');
                            else $(this).addClass('tzebra_2');
                        }
                    });
                }
            });
        }
    }

};