$(function(){
	
	
	
	// smooth scrolling
	
	
	if ( !$.browser.opera )
	{
			$('a.smooth').click(function() {
				
				
				
		    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		        && location.hostname == this.hostname) {
		            var $target = $(this.hash);
		            $target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
		            if ($target.length) {
		                var targetOffset = $target.offset().top;
		                $('html,body').animate({scrollTop: targetOffset}, 1000);
		                return false;
		            }
		        }
		        
		        
		        
		        
		    });
	}
	
	
	
	$(".tabs").tabs();
	$(".button").button();
	
/*	$("a[rel^='prettyPhoto']").prettyPhoto({
		theme: "dark_rounded",
		opacity: 0.9
	}); */
	
	applyHover(".social img, #href-koncertek, #mp3-skull");
	

	$(".zenekar-entry").mouseenter(function(){
		
		$(this).children('.info').slideDown('fast');
		
		
	}).mouseleave(function(){
		
		
		$(this).children('.info').slideUp('fast');
		
	})
	
	
	
	if ( cwReadCookie("pop1") != "ok" ){
		
		cwCreateCookie("pop1", "ok", 1); 
		
		$.prettyPhoto.open(MAINURL + '/images/ujnapvar-tour.jpg','','');
		
	}
	
	
	
	/* commment valiation */
	
	    var rules = { 
            
            errorClass: "invalid",
            
            errorElement: "span",
            
            rules : {
                        
                        author: "required",
                        comment: "required",
                        email: {
                            required: true,
                            email: true
                        }
            },
                    
             messages : {
                       author: "Kérlek, add meg a neved!",
                       comment: "Kérlek, add meg a hozzászólásod szövegét!",
                       email: "Kérlek, add meg helyesen az e-mail címedet!"
             }

        }
    
        $( "#commentform" ).validate( rules );
	
	
	
	
	
	
		/* gallery */
		
		$("#accordion").accordion({
			duration: 100,
			autoHeight: false,
			collapsible: true,
			active: false
		});
		
	
	
		$("#menu-media").mouseenter(function(){
			
			var media_pos = $(this).position();
			var media_half = media_pos.left + ($(this).width() / 2);
			
			$("#dropdown").css({
					"left": media_half - ($("#dropdown").width()/2) + 10 + "px",
					"top": media_pos.top+48+"px",
			}).fadeIn(500);
			
			$("#dropdown").data("enter", 1);
			
		}).mouseleave(function(){
			
			
				$("#dropdown").delay(1000).fadeOut(500);
			
		})
		
		
		
		
		$("#dropdown").mouseenter(function(){
			
			$("#dropdown").clearQueue();
			
		}).mouseleave(function(){
			
			$(this).delay(500).fadeOut(500);
			
		})
		
		

	
	
})





function applyHover( elements ){
	
	$(elements).each(function(){
		
		$(this).mouseover(function(){
			$(this).data( "original", $(this).attr("src") )	
			$(this).attr("src", $(this).attr("rel"));
			
		})
		
		$(this).mouseout(function(){
			$(this).attr("src", $(this).data("original") );
		})

	})
	
	
}



  function cwCreateCookie(name, value, days){
       if (days) {
           var date = new Date();
           date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
           var expires = "; expires=" + date.toGMTString();
       }
       else 
           var expires = "";
       document.cookie = name + "=" + value + expires + "; path=/";
   }
   
   function cwReadCookie(name){
       var nameEQ = name + "=";
       var ca = document.cookie.split(';');
       for (var i = 0; i < ca.length; i++) {
           var c = ca[i];
           while (c.charAt(0) == ' ') 
               c = c.substring(1, c.length);
           if (c.indexOf(nameEQ) == 0) 
               return c.substring(nameEQ.length, c.length);
       }
       return null;
   }

