$(document).ready(function(){
	
	$('#top img[title]').qtip({
		style: 'dark'
	});
	
	$('#phone').click(function(){
		$.get('/subpages/iphone.php', function(data){
			jQuery.facebox(data);
		});
	});
	
	$('#facebook_like').click(function(e){
		e.preventDefault();
		$.get('/subpages/facebook.php', function(data){
			jQuery.facebox(data);
		});
	});
	
	$('#me_like').click(function(){
		$.get('/subpages/like.php', function(data){
			
			jQuery.facebox(data);
			
			$('#me_like_form .v_name').focus(function(){
				if($(this).val() == 'Visningsnamn'){
					$(this).val('');
				}
			});
			
			$('#me_like_form .v_name').blur(function(){
				if($(this).val() == ''){
					$(this).val('Visningsnamn');
				}
			});
			
			$('#me_like_form').submit(function(e){
				e.preventDefault();
				
				if(!(/^[a-zA-ZåäöÅÄÖ0-9-_ ]{2,20}$/.test($('#me_like_form .v_name').val()))){

					$('#me_like_form #error').html('Ogiltigt visningsnamn').slideDown('slow').delay(1000).slideUp();
					
				} else {
				
					$.post("/ajax.php?method=like", $(this).serialize(), function(data){
						
						if(!data.error){
							document.location.href = '/like/' + data.key;
						} else {
							$('#me_like_form #error').html('Ogiltigt visningsnamn').slideDown('slow').delay(1000).slideUp();
						}
						
					}, "json");
				
				}
				
			});
			
			
		});
	});

});

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-16414520-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

