$(function() {

	$('body.single-video embed').attr('wmode', 'opaque');
	$('body.single-video object').append('<param name="wmode" value="transparent">');


	$('#featured').cycle({
		fx:     'fade',
		timeout: 5000,
		next: '#next',
		prev: '#prev'
	});

	$('#menu-item-16').bind('click', function() {
		if ($('#menu-item-13').is('.active')){
			if ($.browser.msie && $.browser.version == 7) { $('#verksteddeler').fadeToggle(); }
			else { $('#verksteddeler').slideToggle(); }
			$('#menu-item-13').removeClass('active');
		}
		if ($('li').is('.active')) {
			$(this).removeClass('active');
			$('#nav li.tmp-current-menu-item').addClass('current-menu-item');
			$('#nav li.tmp-current_page_item').addClass('current_page_item');
		}
		else {
			$(this).addClass('active');
			$('#nav li.current-menu-item').addClass('tmp-current-menu-item').removeClass('current-menu-item');
			$('#nav li.current_page_item').addClass('tmp-current_page_item').removeClass('current_page_item');
		}
		if ($.browser.msie && $.browser.version == 7) { $('#newcar').fadeToggle(); }
		else { $('#newcar').slideToggle(); }
		return false;
	})

	$('#menu-item-13').bind('click', function() {
		if ($('#menu-item-16').is('.active')){
			if ($.browser.msie && $.browser.version == 7) { $('#newcar').fadeToggle(); }
			else { $('#newcar').slideToggle(); }
			$('#menu-item-16').removeClass('active');
		}
		if ($('li').is('.active')) {
			$(this).removeClass('active');
			$('#nav li.tmp-current-menu-item').addClass('current-menu-item');
			$('#nav li.tmp-current_page_item').addClass('current_page_item');
		}
		else {
			$(this).addClass('active');
			$('#nav li.current-menu-item').addClass('tmp-current-menu-item').removeClass('current-menu-item');
			$('#nav li.current_page_item').addClass('tmp-current_page_item').removeClass('current_page_item');
		}
		if ($.browser.msie && $.browser.version == 7) { $('#verksteddeler').fadeToggle(); }
		else { $('#verksteddeler').slideToggle(); }
		return false;
	})

	if ($('#map_canvas').length) {
		var haugesund = new google.maps.LatLng(59.39694,5.302232);
		var odda = new google.maps.LatLng(60.062437,6.55095);
		var marker;
		var map;

		function initialize(pos) {
		  var mapOptions = {
		    zoom: 13,
			panControl: false,
			zoomControl: true,
			mapTypeControl: false,
			scaleControl: false,
			streetViewControl: false,
		    mapTypeId: google.maps.MapTypeId.ROADMAP,
		    center: pos
		  };

		  map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
		var image = '/wp-content/themes/laastad/images/gmaps.png';

		marker = new google.maps.Marker({
			map: map,
			icon: image,
		    draggable: true,
		    animation: google.maps.Animation.DROP,
		    position: pos
		  });
			google.maps.event.addListener(marker, 'click', toggleBounce);
			$('#odda').bind('click', function(){
				initialize(odda);
				$('.content.Haugesund').hide();
				$('.content.Odda').show();
				$('#haugesund').removeClass('locactive');
				$('#odda').addClass('locactive');
				$('.avdeling.Haugesund').hide();
				$('.avdeling.Odda').show();
			})
			$('#haugesund').bind('click', function(){
				initialize(haugesund);
				$('.content.Odda').hide();
				$('.content.Haugesund').show();
				$('#odda').removeClass('locactive');
				$('#haugesund').addClass('locactive');
				$('.avdeling.Odda').hide();
				$('.avdeling.Haugesund').show();
			})
		}

		function toggleBounce() {
			if (marker.getAnimation() != null) {
				marker.setAnimation(null);
			}
			else {
				marker.setAnimation(google.maps.Animation.BOUNCE);
			}
		}
		
		initialize(haugesund);
	}

	if($('body').hasClass('parent-pageid-114')){
		var hash = decodeURI(window.location.hash.slice(1));
		if(hash != ""){
			$('input[name=text-700]').val(hash);
		}
	}
	if($('body').hasClass('page-id-116')){
		$('input[name=radio-432]').selected();
		$('input[name=radio-326]').selected();
		$('input[value=Telefon]').selected();
	}
});
