$(document).ready(function() {
	
	//home slider tabs
	$("#featured").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);
	
	//home newslider read more link
	$("#featured li span").click(function() { window.location.href = $(this).attr('rel'); });
	
	//admin tabs
	$("#tabs").tabs();
	 
	//add class to the last colom on homepage
	$('#cols .col:last').addClass('last');
	
	//cufon init
	Cufon.replace('h1,h2, #productsearch #sort span, #cols .col .head, #cols .col .bottom, #menu ul li a, #persons .person .name', { hover:true});
	
	//give the black bar in the colom a litle opacity
//	$(".col .bottom").fadeTo(0, 0.9);
	
	//fancybox init, used by the product view
	$("a.group").fancybox({
		'speedIn'		:	300, 
		'speedOut'		:	350, 
		'overlayShow'	:	true,
		'onStart' : function(){ $('#trailer').hide(); }, 
		'onClosed' : function(){ $('#trailer').show(); }
	});
	
	//image product slider
	$("#mycarousel").jcarousel({
	
	});
	
	//append a div for the ajax load, used for the "over ons" page
	$('.person').click(function() {	
		$('div.name').attr('id', '');
		$(this).children('div.name').attr('id', 'active');
		$('#personplaceholder').fadeOut('fast').html('').append('<img src="' + webroot + 'img/ajax-loader.gif">').stop(true, true).fadeIn('normal');
		$('#personplaceholder').load($(this).attr('rel'), function() { Cufon.replace('h1')});
	});	
	
	//used in admin news add
	$('#NewsitemTitle').change(function() {
		$('#NewsitemTitletext').val($(this).val());
	});
	
	//used in admin
	current = $('#fragment-3 table tr').size();
	$('a#addCredit').click(function() {
		current++;
		append = '<tr class="' + current + '"><td><input name="data[ProductCredit][' + current + '][function]" type="text" style="width:190px" /></td><td><input class="' + current + '" name="data[ProductCredit][' + current + '][name]" type="text" style="width:400px"> <a class="' + current + '" href="#">[link]</a></td></tr>';
		$('#fragment-3 table').append(append);
		addlink(3);
	});
	
	currentLoc = $('#fragment-2 table tr').length;
	$('a#addLocation').click(function() {
		currentLoc++;
		append = '<tr><td><input name="data[ProductLocation]['+currentLoc+'][date]" type="text" style="width:140px" /></td><td><input name="data[ProductLocation]['+currentLoc+'][location]" class="' + currentLoc + '" type="text" style="width:400px" /> <a class="' + currentLoc + '" href="#">[link]</a></td></tr>';
		$('#fragment-2 table').append(append);
		addlink(2);
	});
	
	currentCe = $('#fragment-5 table tr').length;
	$('a#addCreditEn').click(function() {
		currentCe++;
		append = '<tr><td><input name="data[ProductCredit][' + currentCe + '][function_en]" type="text" style="width:190px" /></td><td><input  class="' + currentCe + '" name="data[ProductCredit][' + currentCe + '][name_en]" type="text" style="width:400px"> <a class="' + currentCe + '" href="#">[link]</a></td></tr>';
		$('#fragment-5 table').append(append);
		addlink(5);

	});
	
	currentImage = 7;
	$('a#addImage').click(function() {
		currentImage++;
		append = '<tr><td><div class="input file"><input type="file" name="data[ProductImage][imageFiles]['+currentImage+']" /></div></td></tr>';
		$('#ProductImageAddForm table').append(append);
	});
	
	//jcrop
	//$('#crop').Jcrop({onSelect: updateCoords,aspectRatio:5/18,
	//$('#crop').Jcrop({onSelect: updateCoords});
	addlink(2);addlink(3);addlink(5);

});
