(function($){
	
	$(document).ready(function(){
		
		$(document).bind("contextmenu",function(e){
        	return false;
    	});
	});
	
	$.fn.menu_hover = function(){
		$('li.headlink > ul > li').hover(function(){
			$(this).css('background-color', '#353d48');
		}, function(){
			$(this).css('background-color', '#54585e');
		});
		$('li.headlink').hover(function(){
			if(!$(this).hasClass('animated')){
				$(this).children('ul').dequeue().stop().slideDown('fast');
			}
		}, function(){
			$(this).addClass('animated').children('ul').slideUp('fast', function(){
				$(this).parent('li').removeClass('animated');
				$(this).dequeue();
			});
		});
	}
	
	$.fn.hidder = function(){
		
		var back = $($('.image').get(0)).css('background-image');
		var root = $($('.image').get(0));
		
		if(back != undefined && back != 'none'){
			var h = $('img', root).outerHeight();
			root.css('height', h+'px !important');
			
			$('img', root).hover(function(){
				$(this).css('opacity', '0');
			}, function(){
				$(this).css('opacity', '1');
			});
		}
		
	}
		
	$.fn.raver = function(){
		
		setInterval(function(){
			
			var div = $('#raver > div > em');
			var span_div = $('#raver > div > span');
			
			if($('#raver > div').attr('class') > 1){
				$.get('api/get_rave/'+$('#raver > div').attr('id'), function(data){
					if(data != 'false'){
						$(div).fadeOut();
						$(span_div).fadeOut(function(){
							$(div).remove();
							$(span_div).remove();
							var id = $(data).attr('id');
							var clas = $(data).attr('class');
							em = $($('em', data).get(0));
							span = $('span', data);
							$(em).prependTo('#raver > div').hide().fadeIn();
							$(span).prependTo('#raver > div').hide().fadeIn();
							$('#raver > div').attr('id', id).attr('class', clas);
						});
					}
				});
			}
			
						
		}, 8000);
		
	}
	
	$.fn.resizer = function(){
		
	  	var imgwidth = $(this).width();
		var imgheight = $(this).height();
 
      	var winwidth = $(window).width();
      	var winheight = $(window).height();
 
      	var widthratio = winwidth / imgwidth;
      	var heightratio = winheight / imgheight;
 
      	var widthdiff = heightratio * imgwidth;
      	var heightdiff = widthratio * imgheight;
 
      	if(heightdiff>winheight) {
        	$(this).css({
          		width: winwidth+'px',
          		height: heightdiff+'px'
        	});
     	} else {
        	$(this).css({
          	width: widthdiff+'px',
          	height: winheight+'px'
        });		
      }
    } 
	
	$(document).ready(function(){
		$.fn.menu_hover();
		$(document).pngFix();
		//$.fn.raver();
		
		$('.blaf').resizer();
		$(window).resize(function(){
			$('.blaf').resizer();
		});
		
		$('.for_background div').each(function(){
			$(this).width($(window).width()+18)
		});
		
		$('.for_background').cycle({
			fx : 'fade',
			timeout : 6000,
			speedOut : 4000
		});
		
		$('#rave_block').cycle({
			fx : 'fade',
			timeout : 8000
		});
		
		
		
		if($('#white').size() > 0 && $('#roles li ').size() > 4){
			
			var lh = 0;
			cl = $('#white > li').each(function(){
				lh += $(this).outerHeight();
			});
			plh = $('.position_left').outerHeight()//+$('.position_left > div > span').outerHeight();
			if(plh > lh){
				lh = plh-22-40;
			}
			$('#bottom_holder').css('bottom', lh + 'px');
			$('#content').css('marginBottom', lh + 70 + 'px');
		}
		else if($('#white').size() > 0){
			$('#bottom_holder').css('bottom', 55 + 'px');
			$('#content').css('marginBottom', 55 + 70 + 'px');
		}
		else{
			$('#bottom_holder').css('bottom', 55 + 'px');	
		}
		
		/*if($('#raver').size() > 0){
			
			h = $('#raver').outerHeight()+$('#raver > div > span').outerHeight()+10-$('.position_right').outerHeight();
			b = parseInt($('#bottom_holder').css('bottom'));
			$('#bottom_holder').css('bottom', b+h+'px');
			
		}*/
			
	});
	
	$(window).load(function(){
		$.fn.hidder();
		
		var h = $('.image img').height();
	});
	
})(jQuery)
