$(document).ready(function() {
	definiendum();
});
function definiendum(){
	$('dfn').css({'display':'none'});
	$('.definiendum').each(function(){
		var fHtml = $(this).html();
		$(this).before($(document.createElement('a'))
			.html(fHtml)
			.append($(document.createElement('span'))
				.addClass('define_down'))
			.addClass('simple')
			.css({'display':'block', 'color':'#555555'})
			.attr('href', 'javascript:void(0);')
			.each(function(){
				$(this).bind('click', function(){
					$(this)
						.find('span')
						.toggleClass('define_up');
					$(this)
						.find('+ dfn')
						.animate({ 
							height: "toggle", 
							opacity:"toggle" 
						}, 500);
				});
			})
		)
		.remove();
	});
}
function inputInfo(fElement, fValue){
	var fPassword = ($(fElement).attr('type') == 'password');
	
	function focus(){
		if($(fElement).attr('value') == fValue && !fPassword){
			$(fElement)
				.css({
					'fontStyle':'normal',
					'color':'#000000'
				})
				.attr('value', '');
		}
		else if($(fElement).attr('value') == '' && fPassword){
			$(fElement)
				.css('background', 'none');
		}
	}
	function blur(){
		if($(fElement).attr('value') == ''){
			if(fPassword){
				$(fElement)
					.css('background', 'url(/images/wachtwoord.gif) no-repeat left center');
			}
			else{
				$(fElement)
					.css({
						'fontStyle':'italic',
						'color':'#999999'
					})
					.attr('value', fValue);
			}
		}
	}
	
	
	$(fElement)
		.bind('focus', focus)
		.bind('blur', blur);
	
	blur();
}
function mail(fTo){
	location.href = 'mailto:'+ fTo +'@vepagifts.nl';
}
function video(fV, fTitle, fHome){
	function volume(fNumber){
		for(i=1; i<5; i++){
			if(i <= fNumber)
				$('#vc_volume_'+ i).addClass('on');
			else
				$('#vc_volume_'+ i).removeClass('on');
		}
		youtube.volume(fNumber * 25);
	}
	function close(){
		youtube.stop();
		youtube.clearVideo();
		$('#video').remove();
	}
	
	
	if(fHome){
		$('#home_video').empty();
		
		$('#home_video').prepend('<div id="youtube"></div>');
		
		fWidth = '300';
		fHeight = '200';
	}
	else{
		$('body').prepend(''
			+'<div id="video">'
				+'<div id="video_fg">'
					+'<div id="video_player">'
						+'<div id="youtube"></div>'
						+'<div id="youtube_screen"></div>'
						+'<div id="video_controls_top">'
							+'<a id="vc_play_pause" href="javascript:void(0);"></a>'
							+'<a id="vc_stop" href="javascript:void(0);"></a>'
							+'<div id="vc_volume">'
								+'<a id="vc_volume_1" class="on" href="javascript:void(0);"></a>'
								+'<a id="vc_volume_2" class="on" href="javascript:void(0);"></a>'
								+'<a id="vc_volume_3" class="on" href="javascript:void(0);"></a>'
								+'<a id="vc_volume_4" class="on" href="javascript:void(0);"></a>'
							+'</div>'
						+'</div>'
						+'<div id="video_controls_bottom">'
							+'<span>'+ fTitle +'</span>'
							+'<a id="vc_close" href="javascript:void(0);"></a>'
							+'<div id="vc_yt">Powered by YouTube</div>'
						+'</div>'
					+'</div>'
				+'</div>'
				+'<div id="video_bg"></div>'
			+'</div>');
		fWidth = '620';
		fHeight = '440';
	}
	
	$('#vc_play_pause').bind('click', youtube.play_pause);
	$('#vc_stop').bind('click', youtube.stop);
	$('#vc_volume_1').bind('click', function(){volume(1);});
	$('#vc_volume_2').bind('click', function(){volume(2);});
	$('#vc_volume_3').bind('click', function(){volume(3);});
	$('#vc_volume_4').bind('click', function(){volume(4);});
	$('#vc_close').bind('click', close);
	
	swfobject.embedSWF('http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytplayer', 'youtube', fWidth, fHeight, '8', null, null, {allowScriptAccess:'always', wmode:'opaque'}, {id:'myytplayer'});
	youtube.loadNewVideo(fV);
}
function message(fTitle, fMessage, fButtons){
	function close(){
		$(oContainer).remove();
	}
	
	var oContainer = $(document.createElement('div'))
			.addClass('popup_msg')
			.append($(document.createElement('div'))
				.addClass('popup_fg')
				.append($(document.createElement('div'))
					.addClass('popup_title')
					.html(fTitle)
					.append($(document.createElement('a'))
						.attr('href', 'javascript:void(0)')
						.text('x')
					)
				)
				.append($(document.createElement('span'))
					.html(fMessage)
				)
				.append($(document.createElement('div'))
					.addClass('popup_buttons')
					.append(fButtons)
				)
			)
			.append($(document.createElement('div'))
				.addClass('popup_bg')
			);
	
	$(oContainer).find('fieldset div a').addClass('button');
	$(oContainer).find('a').bind('click', close);
	$(oContainer).appendTo('body');
}
function Alert(fMessage, fTitle, fFunction){
	if(!fTitle)
		fTitle = 'Melding';
	
		var oOk = $(document.createElement('a'))
				.attr('href', 'javascript:void(0)')
				.html('Ok');
			if(fFunction)
				$(oOk).bind('click', fFunction);
					
	message(fTitle, fMessage, oOk);
}
function Confirm(fTitle, fMessage, fFunction){
	var oTable = $(document.createElement('table'))
			.append($(document.createElement('tbody'))
				.append($(document.createElement('tr'))
					.append($(document.createElement('td'))
						.append($(document.createElement('a'))
							.attr('href', 'javascript:void(0)')
							.bind('click', fFunction)
							.text('Yes')
						)
					)
					.append($(document.createElement('td'))
						.append($(document.createElement('a'))
							.attr('href', 'javascript:void(0)')
							.text('No')
						)
					)
				)
			);
			
	message(fTitle, fMessage, oTable);
}
function form(fAction, fArray){
	var oForm = $(document.createElement('form'))
			.attr({'action':fAction, 'method':'post'});
	
	for(fName in fArray){
		$(oForm).append($(document.createElement('input'))
				.attr({
					'type':'hidden',
					'name':fName,
					'value':fArray[fName]
				})
			);
	}
	
	$(oForm).appendTo('body').submit();
}
function productPage(){
	function ProductPages(){
		function makeA(fProductPage, fName){
			if(!fName)
				fName = fProductPage;
			
			return $(document.createElement('a'))
				.attr('href','#'+ fProductPage)
				.bind('click', function(){
					products(fProductPage);
				})
				.text(fName);
		}
		fFirst = fCurrentPage - 2;
		fLast = fCurrentPage + 2;
			
		if(fLast < 5)
			fLast = 5;
		
		if(fLast > fPages){
			fFirst = fFirst - (fLast - fPages);
			fLast = fPages;
		}
			
		if(fFirst < 1)
			fFirst = 1;
		
		fDiv = $('#product_pages');
		
		if(fFirst == 1)
			fDiv.append($(document.createElement('div')).addClass('page_index_left').text('Vorige'));
		else
			fDiv.append(makeA(fCurrentPage - 1, 'Vorige').addClass('page_index_left'));
		
		fSpan = $(document.createElement('span')).appendTo(fDiv);
		
		if(fFirst > 1){
			fSpan.append(makeA(1));
		}
		if(fFirst > 2)
			fSpan.append($(document.createElement('span')).text('...'));
		
		for(var i=fFirst; i<=fLast; i++){
			var fA = makeA(i);
			
			if(i == fCurrentPage)
				fA.addClass('current');
			
			fSpan.append(fA);
		}
		
		if(fLast < (fPages - 1))
			fSpan.append($(document.createElement('span')).text('...'));
		if(fLast < fPages)
			fSpan.append(makeA(fPages));
			
		if(fLast == fPages)
			fDiv.append($(document.createElement('div')).addClass('page_index_right').text('Volgende'));
		else
			fDiv.append(makeA(fCurrentPage + 1, 'Volgende').addClass('page_index_right'));
	}
	function products(fPage){
		if(fCurrentPage != fPage){
			if(fCurrentPage > fPages)
				fCurrentPage = fPages;
			
			fCurrentPage = fPage;
			$('#product_list').empty();
			$('#product_pages').empty();
			
			vLoader = $(document.createElement('div'))
				.attr('id', 'product_loader')
				.text('Product worden geladen')
				.appendTo('#product_list');
			
			fPage -= 1;
			
			fProductIds = '';
			for(i=0; i<20; i++){
				if(vProducts[((fPage * 20) + i)])
					fProductIds += ','+ vProducts[((fPage * 20) + i)];
			}
			
			$.getJSON('/ajax/producten.asp', {products:fProductIds.substr(1)}, function(fData){
				$('#product_list').empty();
				
				for(var i=0; i<fData.length; i++){
					$('#product_list')
						.append($(document.createElement('a'))
							.attr('href', fData[i].Link)
							.append($(document.createElement('img'))
								.addClass('left')
								.attr({
									'src':'/producten/images/kl_'+ fData[i].Image,
									'title':fData[i].Head,
									'alt':fData[i].Head
								}))
							.append($(document.createElement('span'))
								.text(fData[i].Head)));
				}
				
				ProductPages();
			});
		}
	}
	fPages = Math.ceil((vProducts.length + 1) / 20);
	fCurrentPage = 0;
	
	fPageIndex = location.href.indexOf('#');
	if(fPageIndex > 0)
		products(parseInt(location.href.substr(fPageIndex + 1)));
	else
		products(1);
}