jQuery(document).ready(function(){

			jQuery('#minislider').cycle({
			  fx: 'fade',
			  speed:300,
			  easing: 'easeInOutQuad',
			  cleartype:  1,
			  pause:1,
			  timeout: 5000
			  

			});		
										  
			sliderPosition();							  
										  
			jQuery(".pf").hover(function(){
					jQuery(".info-more:hidden",this).fadeIn('fast');
					},function(){
					jQuery(".info-more",this).fadeOut('fast');
				
			});
			
			jQuery("#filtersubmit").click(function () {
																									  
							var selected_cabin_series = jQuery('#select_cabin_series option:selected').val();
							var selected_cabin_type = jQuery('#select_cabin_type option:selected').val();
							var selected_cabin_bedrooms = jQuery('#select_cabin_bedrooms option:selected').val();
							
							//var active = jQuery('#classholder').html();
							//alert(active);
							var activeclass = selected_cabin_series + '_' + selected_cabin_type + '_' + selected_cabin_bedrooms;
							//alert(activeclass);
						
							
							jQuery('.pf').each(function(){
							
							if(jQuery(this).hasClass(activeclass)){
							jQuery(this).fadeOut('fast').delay('500').fadeIn();
							}
							
							
							else{
								jQuery(this).fadeOut('fast');
								}
													 
							});
		
					return false;
			});
			
			
			jQuery("#filtersubmit_house").click(function () {
																									  
							
							var selected_house_tomt = jQuery('#select_house_tomt option:selected').val();
							var selected_house_floors = jQuery('#select_house_floors option:selected').val();
							var selected_house_bedrooms = jQuery('#select_house_bedrooms option:selected').val();
														
							//var active = jQuery('#classholder').html();
							//alert(active);
							var activeclass = selected_house_tomt + '_' + selected_house_floors + '_' + selected_house_bedrooms;
							//alert(activeclass);
						
							
							jQuery('.pf').each(function(){
							
							if(jQuery(this).hasClass(activeclass)){
							jQuery(this).fadeOut('fast').delay('500').fadeIn();
							}
							
							
							else{
								jQuery(this).fadeOut('fast');
								}
													 
							});
		
					return false;
			});
			
  
			//jQuery("#pricetable_cabin").find(".check");
			addColumns();
			
				function addColumns(){
				var myInteger = 0;
				var myInteger2 = 0;
				var myInteger3 = 0;
				var myInteger4 = 0;
				var myInteger5 = 0;
				var myInteger6 = 0;
						
					$('#pricetable_cabin .col1val').each(function() {
					if($(this).hasClass("checkedval" )){
					myInteger += parseInt($(this).html());
					
					}
					});	
					$(".col1valSum").html(myInteger);
					
					$('#pricetable_cabin .col2val').each(function() {
					if($(this).hasClass("checkedval")){
					myInteger2 += parseInt($(this).html());
						
					}
					});	
					$(".col2valSum").html(myInteger2);
				
					$('#pricetable_cabin .col3val').each(function() {
					if($(this).hasClass("checkedval" )){
					myInteger3 += parseInt($(this).html());
						
					}
					});	
					$(".col3valSum").html(myInteger3);
				
					$('#pricetable_cabin .col4val').each(function() {
					if($(this).hasClass("checkedval")){
					myInteger4 += parseInt($(this).html());
						
					}
					});	
					$(".col4valSum").html(myInteger4);
				
					$('#pricetable_cabin .col5val').each(function() {
					if($(this).hasClass("checkedval")){
					myInteger5 += parseInt($(this).html());
						//alert(myInteger);
					}
					});	
					$(".col5valSum").html(myInteger5);
					
					$('#pricetable_cabin .col6val').each(function() {
					if($(this).hasClass("checkedval")){
					myInteger6 += parseInt($(this).html());
						//alert(myInteger);
					}
					});	
					$(".col6valSum").html(myInteger6);
		
				}
				
				
					
					jQuery(".check").each(function(){
					 
					 jQuery(this).siblings().not(".static").css({'opacity':'0.3'});
					 jQuery(this).siblings("td:empty").addClass("nullValue").css({'opacity':'0.3'}).html("");
															 
					jQuery(this).find('input').change(function () {
					
					if (jQuery(this).attr('checked')) {
						  jQuery(this).parent().siblings().not(".static,.nullValue").addClass("checkedval").css({'opacity':'1'});
						  addColumns();
							
					}
					else{
						jQuery(this).parent().siblings().not(".static,.nullValue").removeClass("checkedval").css({'opacity':'0.3'});
						addColumns();
							
						
					}
				});
					
				});
					
				/*	function sumFormat(){
					
					jQuery(".check").each(function(){
						jQuery(this).siblings().not(".nullValue").format({format:"#,###", locale:"se"});												  
					});
					}
					
					function removeFormat(){
					
					jQuery(".check").each(function(){
						jQuery(this).siblings().not(".nullValue").format({format:"0,000", locale:"se"});												  
					});
					}*/
			
			$("a[rel^='prettyPhoto']").prettyPhoto(); 
			//Cufon.replace('h2,h3',{fontFamily: 'sansserif'});
			Cufon.replace('h1', { 
							fontFamily: 'freehand',
							textShadow: '#eee -1px -1px, #fff 1px 1px',
							color: '-linear-gradient(#b51216, #81080a)'
							
							
							});
			portfolioHover();
			
			toggleMenu();
			toggleList();
		
			
			// CYCLE GALLERY
			jQuery('#gallerycycle,#gallerycyclenarrow').cycle({
			  fx: 'fade',
			  speed:300,
			  easing: 'easeInOutQuad',
			  cleartype:  1,
			  pause:0,
			  timeout: 5000,
			  next:  '#next-gallery',
			  prev:  '#prev-gallery'
			});		
			
			jQuery('#galleryslider').cycle({
			  fx: 'fade',
			  speed:300,
			  easing: 'easeInOutQuad',
			  cleartype:  1,
			  pause:0,
			  timeout: 0,
			  next:  '#next-gallery',
			  prev:  '#prev-gallery'

			});		
			
			
			// SHORTCUTS MENU HOVER FUNCTIONS
			jQuery("#shortcuts").hover(function(){
					jQuery("#shortcuts ul li a").css({'background-color':'#333'});
					},function(){
					jQuery("#shortcuts ul li a").css({'background-color':''});
				
			});

			
			// SHORTCUTS MENU HOVER FUNCTIONS
			
			jQuery("#tomt").change(function(){
			
					if ($('#tomt').attr('checked')) {
					  $("#kommune").show();
					}
					
					else  {
					  $("#kommune").hide();
					}
			});

			
	
			tabPanel();
		

});

	function tabPanel(){
			jQuery(".tabcontent").hide(); //Hide all content
			jQuery(".tabcontentwide").hide(); //Hide all content
			jQuery("#tabnav li:first, #tabnav_minimal li:first").addClass("active").fadeIn('fast'); //Activate first tab
			jQuery(".tabcontent:first").show(); //Show first tab content
			jQuery(".tabcontentwide:first" ).show(); //Show first tab content
			
			//On Click Event
			jQuery("#tabnav li, #tabnav_minimal li").click(function() {
																											 
				jQuery("#tabnav li, #tabnav_minimal li").removeClass("active"); //Remove any "active" class
				jQuery(this).addClass("active"); //Add "active" class to selected tab
				jQuery(".tabcontent").hide(); //Hide all content
				jQuery(".tabcontentwide").hide() //Hide all content
				
				var activeTab = jQuery(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
				jQuery(activeTab).stop().fadeIn('fast'); //Fade in the active content
				return false;
			});
		};
	



function portfolioHover(){
			// PORTFOLIO AND GALLERY ZOOM
			jQuery(".portfolio .zoom").css({'opacity':'0'});
			jQuery(".portfolio").hover(function(){
					jQuery(".zoom",this).stop().fadeTo("slow", 1); 
					},function(){
					jQuery(".zoom",this).stop().fadeTo("slow", 0);  
			
			});
			
			
			jQuery(".portfolio").hover(function(){
					jQuery(this).stop().fadeTo("medium", 0.8); 
					},function(){
					jQuery(this).stop().fadeTo("slow", 1);  
			
			});
			}


(function ($) {
  styleSelect = {
    init: function () {
      $('.select-wrap').each(function () {
        $(this).prepend('<span>' + $(this).find('.select option:selected').text() + '</span>');
      });
      $('.select').live('change', function () {
        $(this).prev('span').replaceWith('<span>' + $(this).find('option:selected').text() + '</span>');
      });

    }
  };
  $(document).ready(function () {
    styleSelect.init()
  })
})(jQuery);


function toggleMenu(){
	
	$(".toggle_container").hide(); 

	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	$(".trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow").siblings(".toggle_container").hide("fast");
		$(this).siblings().removeClass("active");	
		return false; //Prevent the browser jump to the link anchor
	});
					
}

function toggleList(){
	
	$(".toggle_ul").hide(); 
	
	$(".hmenu").toggleClass("active").children().next(':first').slideToggle("slow");
	$(".cmenu").toggleClass("active").children().next(':first').slideToggle("slow");

	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	$(".trigg").click(function(e){
									  
		$(this,'a:first').toggleClass("active").children().next().slideToggle("slow");
		$(this,'a:first').parent().siblings().find(".toggle_ul").hide("fast");
		$(this,'a:first').parent().siblings().find(".trigg").removeClass("active");	
		e.preventDefault();
	});
	

		
					
}




$(function() {
	$('a[rel*=external]').click( function() {
		window.open(this.href);
		return false;
	});
});

// JavaScript Document

/* 
 * Cross-browser event handling, by Scott Andrew
 */
function addEvent(element, eventType, lamdaFunction, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(eventType, lamdaFunction, useCapture);
        return true;
    } else if (element.attachEvent) {
        var r = element.attachEvent('on' + eventType, lamdaFunction);
        return r;
    } else {
        return false;
    }
}

/*
 * Clear Default Text: functions for clearing and replacing default text in
 * <input> elements.
 *
 * by Ross Shannon, http://www.yourhtmlsource.com/
 */

addEvent(window, 'load', init, false);

function init() {
    var formInputs = document.getElementsByTagName('input');
    for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        
        if (theInput.type == 'text' && theInput.className.match(/\bcleardefault\b/)) {  
            /* Add event handlers */          
            addEvent(theInput, 'focus', clearDefaultText, false);
            addEvent(theInput, 'blur', replaceDefaultText, false);
            
            /* Save the current value */
            if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            }
        }
    }
}

function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {
        target.value = '';
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == '' && target.defaultText) {
        target.value = target.defaultText;
    }
}


function sliderPosition(){
	
	jQuery(".cabin-menu").fadeOut();
			$(".swichToCabin, .swichToHouse").hide();
			
			
			// OPENCABIN 
			jQuery("#openCabin").click(function(){
			jQuery(this).parent().fadeOut().parent().parent().parent().delay(100).animate({left:'-470px'},{queue:true,duration:500}).children().find(".cabin-menu").delay(1000).fadeIn().parent().find(".loader .helper:hidden").delay(1500).fadeIn().delay(4000).fadeOut();
			
			
				$(".homeSliderHouse").delay(1000).fadeOut();
				$(".swichToCabin, .swichToHouse").delay(500).fadeIn();
			return false;
			});
			
			// OPENHOUSE 
			jQuery("#openHouse").click(function(){
			jQuery(this).parent().fadeOut().parent().parent().parent().delay(100).animate({left:'470px'},{queue:true,duration:500}).children().children(".house-menu").delay(1000).fadeIn().parent().find(".loader .helper:hidden").delay(1500).fadeIn().delay(4000).fadeOut();
			
			
				$(".homeSliderCabin").delay(1000).fadeOut();
				$(".swichToCabin, .swichToHouse").delay(500).fadeIn();
			
			return false;
			
			});
			
			// SWICH FROM CABIN TO HOUSE
			jQuery(".swichToHouse").click(function(){
				
				 $(".house-menu").show();
				 $(".slider-info-cabin").fadeOut();
				 $("#feature-inner").stop().animate({left:'470px'},{queue:true,duration:500});
				 $(".loader").fadeOut('fast').load("/losartikler/husbilde/ #feature", function() {
					Cufon.refresh();
					$(".loader").fadeIn('fast');

				});
				 

				  
				
			});
			
			// SWICH FROM HOUSE TO CABIN
			jQuery(".swichToCabin").click(function(){
				 
				 $("#feature-inner").stop().animate({left:'-470px'},{queue:true,duration:500});
				 $(".loader").fadeOut('fast').load("/losartikler/hyttebilde/ #feature", function() {
					Cufon.refresh();
					$(".loader").fadeIn('fast');
					
				});
				 $(".cabin-menu").show();
				 $(".slider-info-house").fadeOut();
				
			})
			
		
			// Plassere slideshow i forhold til hash
			var path = window.location.href;
			if(path.match(/^.*hytter.*$/)) {
				//alert(path);
			 $("#feature-inner").stop().animate({left:'-470px'},{queue:false,duration:0});
			
			 $(".cabin-menu").delay(500).fadeIn();
			 $(".homeSliderCabin").hide();
			 $(".swichToCabin, .swichToHouse").delay(500).fadeIn();
			} 	
			else if(path.match(/^.*hus.*$/)) {
				//alert(path);
			 $("#feature-inner").stop().animate({left:'470px'},{queue:false,duration:0});
			
			 $(".house-menu").delay(500).fadeIn();
			 $(".homeSliderHouse").hide();
			 $(".swichToCabin, .swichToHouse").delay(500).fadeIn();
			} 	
	
	};


