var boxWebb = false;
var boxIdent = false;
var boxGraphic = false;
var boxInhouse = false;

$(document).ready(function () {
	$(".button_send").click(function () {
		contactUs();
	});
	
	// For the twitter birl
	$("#twitterBird").mouseover(function (){
		$(this).attr("src", "themes/stare/images/layout/support/twitter_mo.jpg");
	});
	
	$("#twitterBird").mouseout(function (){
		$(this).attr("src", "themes/stare/images/layout/support/twitter.jpg");
	});
	
	$(".button_more").click(function ()
	{
		var sName = $(this).attr("title");
		
		theMoreButton(sName);
	});
});

function contactUs ()
{
	var sName = $("#contact_theName").attr("value");
	var sCompany = $("#contact_company").attr("value");
	var sEmail =  $("#contact_email").attr("value");
	var sUrl =  $("#contact_url").attr("value");
	var sMessage =  $("#contact_message").val();
	
	$(".mainPage_contactBox_contentBox_remind").fadeOut('fast');
	
	$(".mainPage_contactBox_contentBox_more").fadeOut('fast');
	
	$(".mainPage_contactBox_contentBox_content div").animate({
		"height" : "120px"
	});
	
	$(".mainPage_contactBox_contentBox_content div").html("<center><img class='mainPage_contactBox_contentBox_contentLoader' src='themes/stare/images/layout/ajax-loader-contact.gif' border='0' alt='Laddar...' /></center>");
	
	$.ajax({
		type: "GET",
		url: "ajax/ajax.contact.php",
		data: "name=" + sName + "&company=" + sCompany + "&email=" + sEmail + "&url=" + sUrl + "&=message=" + sMessage,
		dataType: "xml",
		success: function(xml) {
			var statusCode = $(xml).find("statusCode").text();
			
			if(statusCode == "1")
			{
				$(".mainPage_contactBox_contentBox_content div").slideUp('slow', function (){			
					$(".mainPage_contactBox_contentBox_content div").html("<center><img class='mainPage_contactBox_contentBox_contentLoader' style='margin-top: 90px' src='themes/stare/images/layout/contact/form_sent_tack.jpg' border='0' alt='Tack!' /></center>");
					$(".mainPage_contactBox_contentBox_content div").attr("class", "mainPage_contactBox_thnx");
					$(".mainPage_contactBox_contentBox_content div").css({"height": "340px"});
					
					$(".mainPage_contactBox_contentBox_content div").slideDown('fast');
				});
			}
			else {
				alert("Ett fel uppstod. VŠnligen kontakta oss pŚ info@stare-d.se.");
			}
		}
	});
	
	return false;
}

function theMoreButton (theButton)
{
	if(theButton == "webb")
	{
		active = boxWebb;
	}
	else if(theButton == "ident")
	{
		active = boxIdent;
	}
	else if(theButton == "graphic")
	{
		active = boxGraphic;
	}
	else if(theButton == "inhouse")
	{
		active = boxInhouse;
	}
	
	if(active)
	{
		$(".mainPage_mainBox_contentBox_moreContent[title="+theButton+"]").slideUp('fast', function () {
			var curHeight = $(".mainPage_mainBox_contentBox[title="+theButton+"]").height();
			var newHeight = curHeight - 250;
			$(".mainPage_mainBox_contentBox[title="+theButton+"]").animate({"height" : newHeight + "px"});
			
			// Get the current height
			var curHeightMainBox = $(".mainPage_mainBox[title="+theButton+"]").height();
			var newHeightMainBox = curHeightMainBox - 250;
			$(".mainPage_mainBox[title="+theButton+"]").animate({"height" : newHeightMainBox + "px"});
		});
	}
	else 
	{
		// Get the current height
		var curHeightMainBox = $(".mainPage_mainBox[title="+theButton+"]").height();
		var newHeightMainBox = curHeightMainBox + 250;
		$(".mainPage_mainBox[title="+theButton+"]").animate({"height" : newHeightMainBox + "px"});
		
		var curHeight = $(".mainPage_mainBox_contentBox[title="+theButton+"]").height();
		var newHeight = curHeight + 250;
		$(".mainPage_mainBox_contentBox[title="+theButton+"]").animate({"height" : newHeight + "px"}, function () {
			$(".mainPage_mainBox_contentBox_moreContent[title="+theButton+"]").slideDown('fast');
		});
	}
	
	if(theButton == "webb")
	{
		boxWebb = (active ? false : true);
	}
	else if(theButton == "ident")
	{
		boxIdent = (active ? false : true);
	}
	else if(theButton == "graphic")
	{
		boxGraphic = (active ? false : true);
	}
	else if(theButton == "inhouse")
	{
		boxInhouse = (active ? false : true);
	}
}
