var ie, ie6, ie7;

ie = $.browser.msie;
ie6 = ie && jQuery.browser.version == "6.0";
ie7 = ie && jQuery.browser.version == "7.0";

var optieprijs = 0;
var prodprijs = 0;

if(!ie6)
{
	var file = "https://www.bigbrands.nl/js/fancybox/jquery.fancybox-1.3.1.js";
	document.write('<script type="text/javascript" src="' + file + '"></scr' + 'ipt>'); 
}

function add2cart(page,product){
	
	var quantity=$('select#hoeveelheid').val();
	if ($('select#kleur').length>0) {
		var color=$('select#kleur').val();
	} else { var color="0"; }

	if ($('select#uitvoering').length>0) {
		var uitvoering=$('select#uitvoering').val();
		var uitvoering=uitvoering.split("_");
		var uitvoering=uitvoering[0];
	} else { var option="0"; }
	if ($('select#opties').length>0) {
		var option=$('select#opties').val();
		var option=option.split("_");
		var option=option[0];
	} else { var option="0"; }
	//alert("/includes/shopcart.php?id="+product+"&hoeveelheid="+quantity+"&kleur="+color+"&optie="+option+"&uitvoering="+uitvoering+"&action=add&page="+page);
	document.location.href="/includes/shopcart.php?id="+product+"&hoeveelheid="+quantity+"&kleur="+color+"&optie="+option+"&uitvoering="+uitvoering+"&action=add&page="+page;
}

function setkleurprijs(kleur_id) {
	document.getElementById('prodprijs').innerHTML='&euro; '+akleuren[kleur_id]+',-';
}

function _resizeWindow()
{
	var offset = ie6 || ie7 ? 917 : 162; 
	var dW  = $(document).width();
	
	$('#fancytitle').css('width',(dW-120)+'px');
	$('#fancytitle').css('margin-left','-' + (((dW - $('#container').width()) / 2) + offset ) + 'px');
}

function selecteer(elm,type){
	if(type == 'merk'){
		$('#designSelect').value='';
		//$('#selector1').load('/ajax_selector.php?skipmenu=1&designer_id=&merk_id='+elm.value);
		$('#gekozenMerk').value = elm.value;
	} 
	
	if (type == 'designer'){
		$('#merkSelect').val('');
		//$('#selector1').load('/ajax_selector.php?skipmenu=1&designer_id='+elm.value+'&merk_id=');
		$('#gekozenDesigner').val(elm.value);
	}
	window.location.href = elm.value !='' ? elm.value : '/';
}

// navigatie links
function toggleSubs(id){
	$('#typeSelect').find('.sub').each(function(){
		if($(this).attr('id')!='sub_'+id) {
			$(this).hide('slow');
			$(this).prev().prev().find('span').html('(+)');
		} else {
			$(this).toggle('slow');	
			var h = $(this).prev().prev().find('span').html();
			$(this).prev().prev().find('span').html(h=='(+)'?'( - )':'(+)')
		}
	})
	
}

// Vertalen (Google)
function DoTranslation(url,lang){
	window.top.location.href = lang !='' ? 'http://www.google.com/translate?u='+url+'&langpair=nl|'+lang+'&hl=nl&ie=UTF8' : url;
}

function goURL(url){
	document.location.href = url;
}

// ? 
function lyteflash(url,width,height) {
   var objLink = document.createElement('a');
   objLink.setAttribute('href',url);
   objLink.setAttribute('rel','lyteframe');
   objLink.setAttribute('rev','width:'+width+';height:'+height+';scrolling:no;')
   myLytebox.start(objLink, false, true);
}

// detail pagina
window.onload = document.onload = function(){
	if(ie6)
	{
		$('a[rel=fancyboxbig]').attr('rel','lytebox');
		$('a[rel=fancy_group_sfeer]').attr('rel','lytebox[stalen]');
		$('a[rel=fancy_group_kleur]').attr('rel','lytebox[kleuren]');
	}
}

function uitvoeringSelect(x, y) {
	if (x!=0){
		var prijs_uitvoering = x.split("_");
		var list = document.selectOptie.uitvoering;
		document.getElementById('prodprijs').innerHTML=prijs_uitvoering[1]+",-";
		var listItemText = list.options[list.selectedIndex].text;
		document.getElementById('uitvtekst').innerHTML="Uitvoering:&nbsp;"+listItemText;
		document.getElementById('uitvtekst').style.display="block";
		document.getElementById('uitvtekst').style.visibility="visible";
		prodprijs=prijs_uitvoering[1];
	} else {
		document.getElementById('uitvtekst').innerHTML="&nbsp;";
		document.getElementById('uitvtekst').style.display="none";
		document.getElementById('uitvtekst').style.visibility="hidden";
		prodprijs=0;
	}
	totalize();
}

function totalize() {
	var total = prodprijs;
	 document.getElementById('totaalprijs').innerHTML=total+",-";
}

function optionSelect(x, y, prijs) {
	if (x!=0){
		var prijs_optie = x.split("_");
		var list = document.selectOptie.opties;
		optieprijs = prijs_optie[1];
		var listItemText = list.options[list.selectedIndex].text;
		document.getElementById('optietekst').innerHTML="+&nbsp;"+listItemText;
		document.getElementById('optieprijs').innerHTML=prijs_optie[1]+",-";
		var tp=prijs+parseFloat(prijs_optie[1]);
		var tp=tp.toFixed(2).replace(".", ",");
		document.getElementById('totaalprijs').innerHTML=tp;
		if (navigator.appName=="Microsoft Internet Explorer") {
			document.getElementById('optierow').style.display="block";
		} else {
			document.getElementById('optierow').style.display="table-row";
		}
		document.getElementById('optierow').style.visibility="visible";
	} else {
		document.getElementById('optietekst').innerHTML="&nbsp;";
		document.getElementById('optieprijs').innerHTML="&nbsp;";
		document.getElementById('optierow').style.display="none";
		document.getElementById('optierow').style.visibility="hidden";
	}
}

function printme(id) {
	window.open('/_printen.php?id='+id);

}

$(window).resize(function(){
	_resizeWindow(); 
});
	
$(document).ready(function(){
	if($('#banners').attr('id')) { $('#banners').cycle(); }
	//Cufon.replace("#newNav li a:not(.not)");
	Cufon.replace(".newbutton");
	Cufon.replace(".newbuttonsmall");
	
	$('.intropics').cycle({ 
		fx:      'fade', 
		speed:    2000, 
		timeout:  4000 
	});
	
	// Flash header
	//$('#flashContent').flash({src: site + 'images/header/header.swf', width: '938', height: '190', "wmode":"opaque"});
	
	// Actie product onder aan de sidebar
	//$('#sidebarActieMiddle').height($('#footer').offset().top-$('.last').offset().top-29);
	if ($('#footer').offset().top-$('.last').offset().top>200) 
	{
		$('#sidebarActie').show()
	}
	
	// Language box
	if(window.location.href.indexOf('translate.googleuser')!=-1)
	{
		$('.translate').find('#nl').show(); 
	}
	
	// Slideshow onderaan index pagina
	if($(document).find('.slideshow').attr('class')){
		$.fn.cycle.defaults.speed   = 1000;
		$.fn.cycle.defaults.timeout = 3000;
		$('.slideshow').cycle({
			fx: 'fade'
		});
	}
	
	// Detail pagina
	//if($.fancybox){
		$("a[rel=fancyboxbig],a[rel=fancy_group_sfeer],a[rel=fancy_group_kleur]").fancybox({
			'showCloseButton':false,
			'centerOnScroll':true,
			'overlayOpacity':0.9,
			'overlayColor':'#1E1E1E',
			'overlayShow':true,
			'titlePosition':'outside',
			'padding':5,
			'showNavArrows': false,
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				$('#fancytitle').html(title);
				// Laat de knoppen en titel zien
				$('[rel=fancyelm]').show();
				
				// Eerste foto? terug knop weg
				if(currentIndex==0) { $('#fancyprev').hide(); }
				// Laatste foto? verder knop weg
				if(currentIndex==currentArray.length-1) { $('#fancynext').hide(); }
				
			},
			// Alles weghalen
			'onCleanup': function(){ $('[rel=fancyelm]').hide(); },
			'onStart': function(){ _resizeWindow(); window.scrollTo(0,0); }
		})
	//}
	
	var sliderwidth = $('.fotoslider img').length*97;
	
	$('#slideleft').click(function() {
		var marginleft = parseInt($('.slides').css('margin-left').replace('px',''));
		if(marginleft+391>0) {
			newmargin=0;	
		} else {
			newmargin = marginleft+291;	
		}
		$('.slides').animate({
			'marginLeft':newmargin+'px'
		},500);
	});
	
	$('#slideright').click(function() {
		var marginleft = parseInt($('.slides').css('margin-left').replace('px',''));
		
		if(marginleft-291>(sliderwidth*-1)) {
		
			newmargin = marginleft-291;	
		
			$('.slides').animate({
					'marginLeft':newmargin+'px'
			},500);
		}
	});
});
