//var sincos = sincos || { 'settings': {}, 'behaviors': {}, 'themes': {}, 'locale': {} }; ;
var sincos = sincos || { 'settings': {}, 'behaviors': {}, 'themes': {}, 'locale': {} }; ;
sincos.jsEnabled = document.getElementsByTagName && document.createElement && document.createTextNode && document.documentElement && document.getElementById;



sincos.attachBehaviors = function(context) {
  context = context || document;
  if (sincos.jsEnabled) {
    // Execute all of them.
    jQuery.each(sincos.behaviors, function() {
      this(context);
    });
  }
};


sincos.behaviors.velg_valuta = function (context) {
	$('.velg_valuta select', context).each(function() {
		$(this).change(function() {
			$(this).parent().submit();
		})
		
	})
}

sincos.behaviors.velg_style = function (context) {
	$('.velg_style select', context).each(function() {
		$(this).change(function() {
			$(this).parent().submit();
		})
		
	})
}

sincos.behaviors.velg_produsent = function (context) {
	$('#velg_produsent').change(function()
	{
		if ($(this).val().length>0)
		{
		 	window.location.replace("/produsent/"+$(this).val());
		}
		
	})
}

sincos.behaviors.navmenu = function (context) {
	$("#navmenu-h li,#navmenu-v li").hover( 
		function() { 
			$(this).addClass("menuhover"); 
		}, 
		function() { 
			$(this).removeClass("menuhover"); 
		} 
	); 
}


sincos.behaviors.form_ajax = function (context) {
	$('.produktanmeldelse .button',context).each(function() {
		$(this).click(function () {
			$.post(
				"/ajax/produktanmeldelse", 
				$("#produkt_anmeldelser_form").serialize(),
				function(data) {
					$('.produkt_anmeldelser_form').html(data);
					$('#produkt_anmeldelser_form_validert').each(function(){
						$('#produkt_anmeldelser_form .button').hide();
						$('#produkt_anmeldelser_hjelp').hide();
					});
				}
			);
			return false;
		})
	});
}

sincos.behaviors.facebook_share = function (context) {
	$('.facebook_share', context).each(function() {
		$(this).click(function () {
			alert()
		})
	})
}
/*
<script type="text/javascript"> 
	function fbs_click() { 
		u="<?php echo $urlfacebook ?>";
		t="<?php echo $result['overskrift'] ?>";		
		window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
		return false;
 
	}
		</script>
*/


/*
 * Brukes av kasse/betaling. For å vise betallingstillegg og endre totalprisen
 *
 */
sincos.behaviors.velg_betaling = function (context) {
	// Vi ser etter en <input> classe bet_radio.
	$('input.bet_radio', context).each(function() {
		// 
		if ($('.oversikt .bet_tillegg .pris').html()<0)
		{
			$('.bet_tillegg').show();
		}
		
		$(this).addClass('bet_radio_prosessert');
		
		$(this).has(function(){
			$('input:checked').each(function() {
				if ($(this).attr('tillegg')=='0,00')
				{
					$('.oversikt .total_pris').html( $('.oversikt .total_pris').attr('pris') );
					$('.oversikt .total_moms').html( $('.oversikt .total_moms').attr('moms') );

					$('.bet_tillegg').hide();
				}
				else
				{
					$('.oversikt .total_pris').html($(this).attr('pris'));
					$('.oversikt .total_moms').html($(this).attr('moms'));
					$('.oversikt .bet_tillegg .pris').html($(this).attr('tillegg'));
					$('.oversikt .bet_tillegg .moms').html($(this).attr('tillegg_moms'));

					$('.oversikt .bet_tillegg .tekst').html($(this).attr('tekst'));
					$('.bet_tillegg').show();
				}
				
			})
			
		});
		$(this).click(function() { 
			if ($(this).attr('tillegg')=='0,00')
			{
				$('.oversikt .total_pris').html( $('.oversikt .total_pris').attr('pris') );
				$('.oversikt .total_moms').html( $('.oversikt .total_moms').attr('moms') );

				$('.bet_tillegg').hide();
			}
			else
			{
				$('.oversikt .total_pris').html($(this).attr('pris'));
				$('.oversikt .total_moms').html($(this).attr('moms'));
				$('.oversikt .bet_tillegg .pris').html($(this).attr('tillegg'));
				$('.oversikt .bet_tillegg .moms').html($(this).attr('tillegg_moms'));
				
				$('.oversikt .bet_tillegg .tekst').html($(this).attr('tekst'));
				$('.bet_tillegg').show();
			}
		});
	});
};


// Global Killswitch on the <html> element
if (sincos.jsEnabled) {
  // Global Killswitch on the <html> element
  jQuery(document.documentElement).addClass('js');
  // 'js enabled' cookie
  document.cookie = 'javascript=1; path=/';
  // Attach all behaviors.
  jQuery(document).ready(function() {
    sincos.attachBehaviors(this);
  });
}

sincos.behaviors.collapse = function (context) {
	//alert('context');
};

sincos.behaviors.cookie = function (context) {
	var found=0;
	var i,x,y,cookies=document.cookie.split(";");
	for (i=0;i<cookies.length;i++)
	{
		x=cookies[i].substr(0,cookies[i].indexOf("="));
		y=cookies[i].substr(cookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x=='24db790')
		{
			found=1;
		}
	}
	if (found==0)
	{
		$('.cookie_warning').show();
	}
}









$(document).ready(function() {
	$(".fancybox").fancybox({
		openEffect	: 'none',
		closeEffect	: 'none'
	});
});



$(document).ready(function() {
	$(".various").fancybox({
		maxWidth	: 800,
		maxHeight	: 600,
		fitToView	: false,
		width		: '70%',
		height		: '70%',
		autoSize	: false,
		closeClick	: false,
		openEffect	: 'none',
		closeEffect	: 'none'
	});
});


$(function() {
	$( "input:submit:not(.spraak_bilde):not(.button_kjop):not(.buttonknapp_sok)" ).button();
});




