var pigit = {
	reg_area_init: function() {	
		$('#subscription_email').focus(function(event){
			if ($(this).val() == 'Tu dirección de email') {
				$(this).val('');
			}}).blur(function(event){
				if ($(this).val() == '') {
					$(this).val('Tu dirección de email');
		}});
	
		$('#closemebtn').click(function(event){
			event.preventDefault();
			if (!$.browser.msie) {
				$("#registrationarea").slideUp('slow');
			} else {
				$("#registrationarea").hide();
			}
			$.cookie("open_registrationarea", "NO", { path: '/' });
		});
		
		$('#regarea_open_handle').click(function(event){
			event.preventDefault();
			if ($("#registrationarea").is(":hidden")) {
				if (!$.browser.msie) {
					$("#registrationarea").slideDown('slow');
				} else {
					$("#registrationarea").show();
				}
				$.cookie("open_registrationarea", "YES", { path: '/' });
			} else {
				if (!$.browser.msie) {
					$("#registrationarea").slideUp('slow');
				} else {
					$("#registrationarea").hide();
				}
				$.cookie("open_registrationarea", "NO", { path: '/' });
			}
		});
		
		// No se abre mas automaticamente.
		//if (($.cookie("open_registrationarea") == null || $.cookie("open_registrationarea") == "YES") && $.cookie("keep_registrationarea_closed") == null) {
		//	setTimeout(function() { if (!$.browser.msie) { $("#registrationarea").slideDown('slow'); } else { $("#registrationarea").show(); } }, 2500);
		//}
	},
	fb_init: function() {
	    window.fbAsyncInit = function() {
	    	FB.init({appId: '115350605193651', oauth : true, status: true, cookie: true, xfbml: true});

	        FB.Event.subscribe('auth.login', function(response) {
			try {
				if (response.authResponse) {
					if (location.pathname.search('comprar') == -1) {
						window.location.reload();
						//$('#login_account_box').load('/micuenta/getLoginBox');
					} else {
						window.location.reload();
					} 						
				} else {
					window.location.reload();
				}
			} catch(err) {
				window.location.reload();
			}
		});
	        FB.Event.subscribe('auth.logout', function(response) {
			try {
				if (location.pathname.search('comprar') == -1) {
					$('#login_account_box').load('/micuenta/getLoginBox');
				} else {
					window.location.reload();
				} 						
			} catch(err) {
				window.location.reload();
			}
		});
	    };
	    (function() {
	    	var e = document.createElement('script');
	    	e.type = 'text/javascript';
	    	e.src = document.location.protocol + '//connect.facebook.net/es_LA/all.js';
	    	e.async = true;
	    	document.getElementById('fb-root').appendChild(e);
	    }());

		$('#fb_login_btn').click(function(event){
			event.preventDefault();
			FB.login(null, {scope:'email'});
		});
		
		$('#logout_btn').click(function(event){
			event.preventDefault();
			FB.getLoginStatus(function(response) {
				if (response.status == 'connected') { // logged in and connected user
					FB.logout();
					$.get('/ajax/logout');
				} else {                // no user session available
					window.open($('#logout_btn').attr("href"), '_self');
				}
			});
		});	
	},
	locationSelector_init: function() {
		$('#location_area_select')
			.selectmenu({style:'dropdown', width: 300})
			.bind("change", function(event) {
				$('#register_location_area_title').text($('#location_area_select :selected').text());
				$.post("/ajax/setLocation", 
					   {"area": $(this).val()}, 
						function(data){
						  	window.open('/?o='+Math.round(Math.random()*1000000, 0), '_self');
					   }
				);
			});
		
		$('#register_location_area_title').text($('#location_area_select :selected').text());

	}
};

