
        $(document).ready(function(){
            
            $.fn.clickMenu.setDefaults({arrowSrc:'images/icons/arrow_right_white.png'});

    		$('#navMenu').clickMenu();
            $('div.render').each(function() {
                $(this).flash({
                    src: $(this).attr('title'),
                    width: 260,
                    height: 390,
                    wmode: 'transparent'
                });
            });

            instantiateHoverables();
            instantiateModal();
            instantiateTooltips();
    
            $('#main_search_box').submit(function(){
                
                window.location = $('base').attr('href') + 'search/' + $('#main_search_input').val();
                
                return false;
                
            });
            
            
            
        });
        
        var hoverable_color = '';
        function instantiateHoverables() {
         
            $('.hoverable').mouseover(function() {
                
                if ($(this).find('td').css('background-color') != 'rgb(63, 63, 63)') {
                    
                    hoverable_color = $(this).find('td').css('background-color');
                    
                    $(this).find('td').each(function () {
                        $(this).css('background-color', '#3F3F3F');
                    });
                    
                }
                
            });
            
            $('.hoverable').mouseout(function() {
                
                $(this).find('td').each(function () {
                    $(this).css('background-color', hoverable_color);
                });
                
            });
               
        }
        
        function instantiateTooltips() {
            
            $('.item_icon').each(function() {
            
                $(this).wTooltip({ ajax: 'item/tooltip/' + $(this).attr('id'), className:'itemToolTip' });

            });
            
            $('.rune_icon').each(function() {
            
                $(this).wTooltip({ ajax: 'rune/tooltip/' + $(this).attr('id'), className:'itemToolTip' });

            });
            
            $('.spell_icon').each(function() {
            
                $(this).wTooltip({ ajax: 'spell/tooltip/' + $(this).attr('id'), className:'itemToolTip' });

            });
            
            $('.champion_icon').each(function() {
            
                $(this).wTooltip({ ajax: 'champion/tooltip/' + $(this).attr('id'), className:'itemToolTip' });

            });
            
        }
        
        var box_id = '#dialog';
    	var data_id = '#modal_data';
    	var mask_id = '#mask';
    	
    	var modal_obj;
        	
        function doModal(data, overwrite) {
            
            if (overwrite == undefined) {
                    
                $(data_id).html(data);
                
                if ($.browser.msie) { 
                    
            	   document.getElementById('modal_data').innerHTML = data;
            	
                }
            
            }
            
    		//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_id).css({'width':maskWidth,'height':maskHeight});
    		
    		//transition effect		
    		$(mask_id).fadeIn(300);	
    		$(mask_id).fadeTo("fast",0.9);	
    	
    		//Get the window height and width
    		var winH = $(window).height();
    		var winW = $(window).width();
                  
    		
    		//Set the popup window to center
    	    var top = (((winH/2)-($(box_id).outerHeight())) + $(window).scrollTop());
    	    var left = (((winW/2)-($(box_id).width())) + $(window).scrollLeft());
    	        	    
    		if($.browser.opera){
    		    
    		    var top = (((winH/2)-($(box_id).height() / 2)) + $(window).scrollTop());
    		  
    		}

    		if ($.browser.msie) {
    		    
    		    var top = (((winH/2)-($(box_id).outerHeight() / 2)) + ($(window).scrollTop()));
    		    var left = (((winW/2)-($(box_id).width() / 2)) + ($(window).scrollLeft()));
    		    
    		}
    		
    		if (top < 50) { var top = 50; }
    		
			$(box_id).css('top',  top);
			//$(box_id).css('left', 0); 
    		
    		//transition effect
    		$(box_id).fadeIn(500); 
        		
        		
        }
        
        function closeModal() {
        
    		$(mask_id).hide();
    		$(box_id).hide();
    		
    		if (modal_obj == undefined) {
    		 
    		    $(data_id).html('');
    		       
    		} else {
    		 
    		    $(modal_obj).html($(data_id).html());
    		       
    		}
    		
        }
        
        function instantiateModal() {
            
            $('a[name=modal]').click(function(e) {
        		//Cancel the link behavior
        		e.preventDefault();
        		
        		//Get the A tag
        		var id = $(this).attr('href');
        	    
        		if ($(this).attr('url')) {
        		    
        		    url = $(this).attr('url');
        		    
        		    if (url.indexOf('#') == 0) {
        		        
        		      modal_obj = url;
    		          doModal($(url).html());
        		          
        		    } else {
            		        
        		        modal_obj = undefined;
                		$.get(url, function(data) {
                		    
                            $(data_id).html('');
                            doModal(data);
                            
                        });
                    
        		    }
        		    
        		}
        	
        	});
        	
            //if close button is clicked
        	$('#dialog .close').click(function (e) {
        		//Cancel the link behavior
        		e.preventDefault();
        		closeModal();
        	});		
        	
        	//if mask is clicked
        	$('#mask').click(function () {
        	    closeModal();
        	});
        	
        }
        
        function itemSearch(str) {
            
            $('#datagrid').flexOptions({ url: 'items/search/' + str}); 
            $('#datagrid').flexReload();
            
        }
        
        function itemShopSearch(str) {
            
            $('.item_shop').css({display: 'block'});
            
            $('#item_shop').flexOptions({ url: 'items/shop/' + str}); 
            $('#item_shop').flexReload();
            
        }
        
        function itemFunctionSearch(str) {
            
            $('#datagrid').flexOptions({ url: 'items/fsearch/' + str}); 
            $('#datagrid').flexReload();
            
        }
        
        function runeShopSearch(val, str) {
         
            $('.runes_shop').css({display: 'block'});
            
            $('#runes_shop').flexOptions({ url: 'runes/shop/by'+val+'/' + str}); 
            $('#runes_shop').flexReload();
            
        }
        
        function runeSearch(str, type, tier) {
            
            if (type != undefined) {
                
                $('#datagrid').flexOptions({ url: 'runes/search/by'+type+'/' + tier}); 
                
            } else { 
                
                $('#datagrid').flexOptions({ url: 'runes/search/bystat/' + str}); 
                
            }
            
            $('#datagrid').flexReload();
            
            
        }
        
        function championSearch(str, tag) {

            if (tag != undefined) {
                
                $('#datagrid').flexOptions({ url: 'champions/search/bytag/' + tag});

            } else {

                $('#datagrid').flexOptions({ url: 'champions/search/' + str});

            }
            $('#datagrid').flexReload();

        }
        
        function spellSearch(str) {

            switch (str) {
                
                case 'Champion Abilities':
                case 'Champion Innate':
                case 'Champion Ultimates':
                case 'Champion Regular':
                
                    $("#datagrid").flexigrid ({
            			colModel : [
            				{display: '', name : 'champ', width : 50, sortable : true, align: 'center'},
            				{display: '', name : 'icon', width : 50, align: 'center'},
            				{display: KEYWORD_NAME, name : 'name', width : 180, sortable : true, align: 'left'},
            				{display: KEYWORD_DESCRIPTION, name : 'description', width : 800, sortable : true, align: 'left'}
            				],
            			dataType: 'xml',
            			sortname: "name",
            			sortorder: "asc",
            		    method: 'POST', // data sending method
            			nowrap: false,
            			usepager: true,
            			useTopPager: true,
            			useRp: true,
            			rp: 15,
            			showTableToggleBtn: true,
            			width: "100%",
            		    resizable: false, //resizable table
            			height: "auto" 
            				
                    });
                    $('#datagrid').flexOptions({ 
                            
                        url: 'spells/search/' + str
                    
                    });
                    
                break;
                
                case 'Summoner Spells':
                
                    $("#datagrid").flexigrid ({
            			colModel : [
            				{display: '', name : 'icon', width : 50, align: 'center'},
            				{display: KEYWORD_NAME, name : 'name', width : 180, sortable : true, align: 'left'},
            				{display: KEYWORD_DESCRIPTION, name : 'description', width : 860, sortable : true, align: 'left'}
            				],
            			dataType: 'xml',
            			sortname: "name",
            			sortorder: "asc",
            		    method: 'POST', // data sending method
            			nowrap: false,
            			usepager: true,
            			useTopPager: true,
            			useRp: true,
            			rp: 15,
            			showTableToggleBtn: true,
            			width: "100%",
            		    resizable: false, //resizable table
            			height: "auto" 
                    });
                    $('#datagrid').flexOptions({ 
                        
                        url: 'spells/search/' + str
                    
                    });
                    
                break;
                
            }
            
            $('#datagrid').flexReload();

        }