
$(document).ready(function() {			

	
	// Fix all inline PNG images and the element #container with the custom sizingMethod of "scale"
	//$("img[@src$=png], .top, .bb .comment_share, .bb .date, .proj_box .comment, .bb .comment, .blogg_short .comment").pngFix( );
	
	$(document).pngFix(); 

	$(".alt").focus( function(){
		if(this.value == this.alt) this.value = "";			
	})
	
	$(".alt").blur( function(){
		if(this.value == "") this.value = this.alt;				
	})
	
	$(".b_link").mouseover( function(){
		$(this).parent().removeClass('b_cont_sub');
		$(this).parent().addClass('b_cont_sub_sel');
	})
	
	$(".b_link").mouseout( function(){
		$(this).parent().removeClass('b_cont_sub_sel');
		$(this).parent().addClass('b_cont_sub');
	})

    $(".emp").mouseover(function(){
		$(this).children(".emp_info").children(".extra_info").show();
    }).mouseout(function(){
		$(this).children(".emp_info").children(".extra_info").hide();
    });
	
    $(".partner_img a img").mouseover(function(){
		src = $(this).attr("src");
		new_src = src.replace(/.gif/g, '_colour.gif');
		$(this).attr({
			src: new_src
		});
    });
	
    $(".partner_img a img").mouseout(function(){
		src = $(this).attr("src");
		new_src = src.replace(/_colour.gif/g, '.gif');
		$(this).attr({
			src: new_src
		});
    });


    $(".show_share").click(function(event){		
		event.preventDefault();
		
		if($("#"+$(this).attr("rel")).attr("class")=="sel") {
			$("#"+$(this).attr("rel")).slideUp(400);
			$("#"+$(this).attr("rel")).removeClass("sel");
		}
		else {
			$("#"+$(this).attr("rel")).slideDown(400);
			$("#"+$(this).attr("rel")).addClass("sel");
		}
    });
	
	
    $(".con_click").click(function(event){		
		event.preventDefault();

		var company = $("#con_company").val();
		var email = $("#con_email").val();
		var phone = $("#con_phone").val();
		var time = $("#con_time").val();
		
		if(time==$("#con_time").attr("alt")) {
			time = "";
		}

		var error = false;

		if(!validateEmail(email)) {
			$("#con_email").css({'background-color':'#F57E6D'});
			error = true;
		} 
		else $("#con_email").css({'background-color' : ''});
		
		if(company.length==0 || company==$("#con_company").attr("alt")) {
			$("#con_company").css({'background-color' : '#F57E6D'});
			error = true;
		} 	
		else $("#con_company").css({'background-color' : ''});
		
		if(phone.length==0 || phone==$("#con_phone").attr("alt")) {
			$("#con_phone").css({'background-color' : '#F57E6D'});
			error = true;
		} 	
		else $("#con_phone").css({'background-color' : ''});

		if(!error) {
			if(ajaxValue("/include/ajax/basic/contact.php", "company="+company+"&email="+email+"&phone="+phone+"&time="+time)==1) {
				$("#con_info").html("Tack! Vi kontaktar dig så snart vi kan!");
				$("#con_company").val($("#con_company").attr("alt"));
				$("#con_email").val($("#con_email").attr("alt"));
				$("#con_phone").val($("#con_phone").attr("alt"));
				$("#con_time").val($("#con_time").attr("alt"));
				$("#con_info").show();
			}
			else {
				$("#con_info").html("FEL: Kunde inte skicka din fråga! Vänligen skicka ett mail till info@jota.se istället.");
				$("#con_info").show();
			}
		}
		
    });
	$(".more_images_button").click(function(event){
		event.preventDefault();
		$(this).parent().siblings('.more_image_cont').children('a:first').trigger('click');
	});	
	$(".more_images_thumb").click(function(event){
		event.preventDefault();
		$(this).siblings('.more_image_cont').children('a:first').trigger('click');
	});	
	
	
});

function ajaxContent(id,path,vars,callback) {
	 $.ajax({
	   type: "POST",
	   url: path,
	   data: vars,
	   success: function(html){
		$(id).html(html);
		if(callback!="") eval(callback);
	   }
	 });
}

function ajaxValue(path, vars) {
	var html = $.ajax({
	type: "POST",
	url: path,
	data: vars,
	cache: false,
	async: false
	}).responseText;	

	return html;
}

function js_url(url) {
	return url.replace('&','%26');
}

function validateEmail(address) {
   var reg = /^([A-Za-z0-9_\-\.\+])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   return reg.test(address);
}
