// JavaScript Document
$(document).ready(function(){
//-------- start scripts ---------

	/* ---- SORT CONTENT BLOCKS ---- */
	$('.pageContainer').sortable({
			handle: '.grabBut',
			connectWith: ".pageContainer",
			items: '.contentBlock',
			placeholder: "ui-state-highlight",
			forcePlaceholderSize: true,
			update: function(){
				var tel = 0;
				//var test = $(this).sortable('toArray');
				//alert(test);
				$('.contentStream', this).each(function(){
					var thisContainer = $(this).parent().parent().attr('id');
					var thisBlock = $(this).attr('id');
					$.ajax({
						url: '/ajax/backend/savepos.php?id='+thisBlock+'&container='+thisContainer+'&pos='+tel,
						type: 'GET'
					})
					tel = tel + 1
				});
			}
		});
	
	/*
	$('.pageContainer').sortable({
			handle: '.grabBut',
			connectWith: ".pageContainer",
			items: '.contentBlock',
			placeholder: "ui-state-highlight",
			forcePlaceholderSize: true,
			update: function() {
				var str
				$('.pageContainer').each(function(){
						str = str + $(this).attr('id') + ':';
						$('.contentStream', this).each(function(){
							str = str + $(this).attr('id');
						})
				});
				$.post('/ajax/backend/savepos2.php',{ 'datas' : str }, function(msg){alert(msg)});
			}
		});
	
	*/
	
	
	
	/* --- TOOLBOX TOOLTIPS ---- */

	$('a[title], span[title]').tooltip({
		position: 'bottom center',
		opacity: 0.8,
		offset: [5,5]
	});
	
	/* ---- EDIT BUTTON ---- */
	$('.editBut').live('click',function(eb){
		eb.preventDefault();
		var id = $(this).parent().next('.contentStream').attr('id');
		var h = $('#'+id).height();
		var w = $('#'+id).width();
		var url = $(this).attr('href');
		$.fancybox({
				   'type' : 'iframe',
				   'href' : url+'&id='+id+'&h='+h+'&w='+w,
				   'width' : w+10,
				   'height' : h+150
				   });
	});
	
	/* ---- DELETE BUTTON ---- */
	$('.delBut').live('click',function(db){
		db.preventDefault();
		var id = $(this).parent().next('.contentStream').attr('id');
		var url = $(this).attr('href');
		$.fancybox({
				   'type' : 'iframe',
				   'href' : url+'?id='+id,
				   });
	});
	
	/* ---- ADD TEXT ----*/
	$('.addContent').click(function(at){
		at.preventDefault();
		var container = $(this).parent().parent().attr('id');
		var type = $(this).attr('href');
		$.fancybox({
			'type': 'iframe',
			'href': '/assets/contentmanager/newContent.php?id='+container+'&type='+type
		});
	});
	
	$('.openUserFiles').click(function(ou){
			var wd = $('body').width() - 50;
			ou.preventDefault();
			var cont = $(this).attr('href');
			$.fancybox({
				   'type' : 'iframe',
				   'href' : '/userfiles/manager.php?ct='+cont,
				   'width': 800,
				   'height' : 550
			});
	});
	
	/*---- CLICK LOCATION ---------*/
	$('.locatie').click(function(){
		var locatie = $(this).attr('title');
		location.href = locatie;						 
	});
	
	
	$('#frmContact').submit(function(cf){
		cf.preventDefault();
		$('#blacker').html('<p>Even geduld aub...</p>');
		$('#blacker').fadeIn();
		$.ajax({
			url: '/contact/processform.php',
			data: $(this).serialize(),
			type: 'POST',
			success: function(contactmsg){
				if(contactmsg == 'ok'){
					location.href = '/contact/danku/bedankt.html';
				} else {
					var errrs = contactmsg.split('&');
					$.each(errrs, function(diskey,diserr){
						var dis = diserr.split('=');
						$('#'+dis[1]).css({'background' : '#f00'});
					});
					$('#blacker').fadeOut();
				}
			}
		});
	});
	
	$('.inputField, textarea, .inputLogin').focus(function(){
		$(this).css({'background' : '#fff'});
	});
	$('.inputField, textarea, .inputLogin').blur(function(){
		$(this).css({'background' : '#ccc'});
	});
	
	
	/*------ go to album ------- */
	$('.galtease').click(function(){
		var album = $(this).attr('title');
		location.href = '/foto/album/'+album+'/foto-album.html';
	});
	
	/*---- go to shop groep ----*/
	$('.shopcat').click(function(){
		var cat = $(this).attr('title');
		location.href = '/shop/groep/'+cat+'/buikdans-winkel.html';
	});
	
	/* ---album --- */
	$("a.showFB").attr('rel', 'album').fancybox({
		overlayOpacity: 0.7,
		overlayColor: '#000'
	});
	
	$("a.fb").click(function(){
		$.fancybox({
			type: 'image',
			href: 	$('img', this).attr('src'),
			overlayOpacity: 0.8,
			overlayColor: '#000',
			padding: 8,
			margin: 8
		});
		return false;
	});
	
	/* ----- PUT IN CART -----*/
	$('.putincart').click(function(putincart){
			putincart.preventDefault();
			var prodje = $(this).attr('href');
			var kleur = $('#kleur_'+prodje).val();
			var maat = $('#maat_'+prodje).val();
			$.ajax({
				   url: '/ajax/frontend/putincart.php?pid='+prodje+'&kleur='+kleur+'&maat='+maat,
				   success: function(msg){
						location.reload();  
				   }
			})
	});
	
	$('#frmBestel').submit(function(cf){
		cf.preventDefault();
		$('#blacker').html('<p>Even geduld aub...</p>');
		$('#blacker').fadeIn();
		$.ajax({
			url: '/shop/processorder.php',
			data: $(this).serialize(),
			type: 'POST',
			success: function(contactmsg){
				if(contactmsg == 'ok'){
					location.href = '/shop/danku/bedankt.html';
				} else {
					var errrs = contactmsg.split('&');
					$.each(errrs, function(diskey,diserr){
						var dis = diserr.split('=');
						$('#'+dis[1]).css({'background' : '#f00'});
					});
					$('#blacker').fadeOut();
				}
			}
		});
	});
	
	$('.delcart').click(function(dc){
		dc.preventDefault();							 
		var p = $(this).attr('href');
		$.ajax({
			url: '/ajax/frontend/removefromcart.php?item='+p,
			type: 'GET',
			success: function(msg){
				location.reload();
			}
		});
	});


/* ALLE FOTO'S IN FANCY BOX */

	$('img').click(function(){
		var pad = $(this).attr('src');						
		$.fancybox({
			'href' : pad		   
		});
	})

//-------- end scripts -----------
});
