$(function(){
	// search box
	$(".searchbox-input, .textbox-blurred")
		.focus(function(){ 
			if($(this).val() == $(this).attr('title')) { 
				$(this).removeClass("onblur").val("");
			}
		})
		.blur(function(){
			if(jQuery.trim($(this).val()) == '' || $(this).val() == $(this).attr('title')) { 
				$(this).addClass("onblur").val($(this).attr('title'));
			}
		})
		.blur();
	$(".searchbox-input").closest('form').submit(function(){
		if($(".searchbox-input").val() == $(".searchbox-input").attr('title')) return false;
	});
	
	// banner
	$("#home-banner ul").simpleslider(
	{
        speed			: 500,
		easing			: 'easeOutCirc',
		direction		: 'vertical',
		buttons			: false,
		auto			: true,
		interval		: 5000
    });
    
    // side menu active items
    $("#side-menu a").each(function(){
    	var href = $(this).attr("href");
    	if(href == window.location.href)
    	{
    		$(this).addClass("active");
    	}
    });
    
    // media gallery zoom
	$("a.fancybox").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		: 200, 
		'speedOut'		: 200, 
		'overlayShow'	:	true
	});
	
	$("a.fancyboxvideo").click(function()
	{
		$.fancybox({
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'speedIn'		: 200, 
			'speedOut'		: 200, 
			'overlayShow'		: true,
			'padding'		: 0,
			'autoScale'		: false,
			'width'			: 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
				'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});
		
		return false;
	});
	
	// inaltime egala pentru coloanele din footer, quick/dirty
	c1 = $('#footer li.c1');
	c2 = $('#footer li.c2');
	c3 = $('#footer li.c3');
	max_height = c1.height() > c2.height() ? c1.height() : c2.height();
	max_height = c3.height() > max_height ? c3.height() : max_height;
	c1.height(max_height);
	c2.height(max_height);
	c3.height(max_height);
	
	// newsletter subscribe
	$("#newsletter form").submit(function(){
		
		$("#nume, #email").removeClass("error");
		
		var nume = $.trim( $("#nume").val() );
		var email = $.trim( $("#email").val() );
		
		if(nume == "")
		{	
			$("#nume").addClass("error").focus();
			return false;
		}
		
		if( !/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email) )
		{
			$("#email").addClass("error").focus();
			return false;
		}
		
		// trimite
		var data_string = 'nume='+ nume + '&email=' + email;  
		$.ajax({  
		  type: "POST",  
		  url: BASE_URL + LANG + "/side_newsletter/subscribe",  
		  data: data_string,  
		  success: function() {  
		    $("#newsletter .message").stop(true, true).slideDown("fast").delay(3000).slideUp("fast");
		  	$("#nume, #email").val("");
		  }  
		}); 
		
		return false;
	});
	
	// hover side gallery
	$("#side-photo-gallery li img").hover(function(){
		$(this).fadeTo(200, 0.8);
	}, function(){
		$(this).fadeTo(100, 1);
	});
})

