function industry()
{
    if ($("input[@name='category']:checked").val() == '9')
	{
		jQuery("#industries_category11").hide();
		jQuery("#industries_category11 input").attr('checked', '');
		jQuery("#industries_category9 input").attr('checked', '');
		jQuery("#industries_category9").show();
	}
	else
	{
		jQuery("#industries_category9").hide();
		jQuery("#industries_category9 input").attr('checked', '');
		jQuery("#industries_category11 input").attr('checked', '');
		jQuery("#industries_category11").show();
	}

}

function expandCommune()
{
	if((jQuery("#districts143").hasClass('hidden') || jQuery("#districts143").length==0) && (jQuery("#districts248").hasClass('hidden') || jQuery("#districts248").length==0) && (jQuery("#districts115").hasClass('hidden') || jQuery("#districts115").length==0) )
	{
		jQuery(".search-commune-list").removeClass('search-commune-list-expand');
	}
	else
	{
		jQuery(".search-commune-list").addClass('search-commune-list-expand');
	}
}

function applyActionsToCommune()
{
	jQuery("#commune143").click(function(e)
	{
		if(jQuery("#districts143"))
		{
		jQuery("#districts143").toggleClass('hidden');
		jQuery("#districts143 input").attr('checked', '');
		expandCommune();
		}
	});
	
	jQuery("#commune248").click(function(e)
	{
		if(jQuery("#districts248"))
		{
		jQuery("#districts248").toggleClass('hidden');
		jQuery("#districts248 input").attr('checked', '');
		expandCommune();
		}
	});
	
	jQuery("#commune115").click(function(e)
	{
		if(jQuery("#districts115"))
		{
		jQuery("#districts115").toggleClass('hidden');
		jQuery("#districts115 input").attr('checked', '');
		expandCommune();
		}
	});
}

jQuery(document).ready(function()
{
	jQuery("input[name='category']").click(industry);
	
	jQuery("#county").change(function()
	{
		jQuery("#commune-list").load('/wp-content/themes/silveray/municipalities.php', {county:jQuery("#county").val()}, applyActionsToCommune);
	});
	
	applyActionsToCommune();
	
	if($("#cycle-group-1"))
	{
	$("#cycle-group-1").cycle();
	}
	if($("#cycle-group-2"))
	{
	$("#cycle-group-2").cycle();
	}
	if($("#cycle-group-ge"))
	{
	$("#cycle-group-ge").cycle();
	}
	if($("#cycle-group-bp"))
	{
	$("#cycle-group-bp").cycle({ 
    fx:    'fade', 
    timeout:  8000 
});
	}	
		
	jQuery("#telephonenumber a").click(function(e)
	{
		jQuery("#telephonenumber").load('/wp-content/themes/silveray/telephone.php', {id:jQuery("#telephonenumber a").attr('href')});
		e.preventDefault();
	});
	
	jQuery("#cellphonenumber a").click(function(e)
	{
		jQuery("#cellphonenumber").load('/wp-content/themes/silveray/cellphone.php', {id:jQuery("#cellphonenumber a").attr('href')});
		e.preventDefault();
	});
	
	
	jQuery("#hyra-start").submit(function(e){
		window.location = window.location + jQuery('#hyra-start input:radio:checked').val();
		e.preventDefault();
	});
	
	jQuery("#first-hyra-button").click(function(e){
		window.location = window.location + jQuery('#first-page-rent-select option:selected').val();
		e.preventDefault();
	});	
	
	jQuery("#first-search-button").click(function(e){
		window.location = window.location + "sok/?category=" + jQuery('#first-page-search-select option:selected').val();
		e.preventDefault();
	});	
	
	jQuery(".thumbnails a").click(function(e)
	{
		jQuery("#main-image").attr("src", jQuery(this).attr('href'));
		e.preventDefault();
	});
	
	if($(".extern-imageviewer a"))
	{
	$(".extern-imageviewer a").colorbox({photo:true, current: "Bild {current} av {total}", previous: "Föregående", next: "Nästa", close: "Stäng"});
	}
	jQuery("#send-interest").submit(function(e){
		jQuery("#interest-form").slideUp(400, function() {
		jQuery("#interest-form").load('/send_em.php', {'mail-send':true, 'mail-to-user': jQuery("#mail-to-user").val(), 'mail-header': jQuery("#mail-header").val(), 'mail-link': jQuery("#mail-link").val(), 'mail-from-name': jQuery("#mail-from-name").val(), 'mail-from-company': jQuery("#mail-from-company").val(), 'mail-from-email': jQuery("#mail-from-email").val(), 'mail-from-phone': jQuery("#mail-from-phone").val(), 'mail-message': jQuery("#mail-message").val(), 'mail-newsletter': jQuery("#mail-newsletter").attr('checked')}, function() {
	jQuery("#interest-form").slideDown();
});
});
		
		e.preventDefault();
	});
	
});

