/**
 * add custom functionality to fancybox
 * note that also the jquery.fancybox.js has some custom source changes
 * @author Jos Deldime (CreOFF)
 */
$(document).ready(function() { 
	
	$("a.single_image").fancybox({
			'imageScale': true,
			/*'callbackOnStart': add_control,
			'callbackOnChange': hide_control,
			'callbackOnShow': newpic,
			'callbackOnClose': remove_control,*/
			'hideOnContentClick': true
	}); 

	/*	
	$("a.send2friend").fancybox({
			frameWidth: 400,
			frameHeight: 300,
			'hideOnContentClick': false

	});  */
	
	/* Using custom settings
	$("a#inline").fancybox({ 'hideOnContentClick': true }); 
	$("a.group").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': false });  
	*/ 
}); 

function add_control() {
	var html = '';
	html += '<div id="fancy_controlbox" style="display:none;">';
	
	html += '<form>';
	html += 'Rating: <span id="stars-cap"></span>';
	html += '<div id="stars-wrapper2">';
	html += '		<select name="selrate">';
	var stars = 5;
	var vote = 2;
	for (var star=0; star<=stars; star++) {
		html += '		<option value="'+star+'" >'+star+'</option>';	
	}
	html += '		</select>';
	html += '</div>';
	html += '</form>';
	
	html += '</div>';
	$(html).prependTo("#fancy_inner");	
	/*
		$("#stars-wrapper2").stars({
								inputType: "select",
								cancelShow: false,
								selected: 0,
								callback: function(ui, type, value){
										// $("#stars-wrapper2").stars("select", value);
										alert("value: "+value);										
									}
								
								});	

	*/
	// alert($("#fancy_controlbox").html());

	/*
	$("#fancy_controlbox").click(function(){
		alert('clicked');
	});
	*/
}

function hide_control() {
	$("#fancy_controlbox").hide();	
	
}

function remove_control() {
	$("#fancy_controlbox").remove();
	
}

function newpic() {
	// this = fancybox
	// item.orig = $(elem).children("img:first");
	// var href = this.itemArray[this.itemCurrent].href;
	var obj = this.itemArray[this.itemCurrent].orig;
	var data = obj.attr("alt").split("/");
	
	
	$("#fancy_controlbox").show();
	// $("#fancy_controlbox").html(data[0]+"got "+data[1]+" votes "+data[2]);								
	
}

function vote() {
	
	$.ajax({
		  type: "POST",
		  url: SITEROOT+'overview/photo',
		  data: { 	
		  			href: this.itemArray[this.itemCurrent].href
		  },
		  dataType: "json",
		  success: function(response){
					
					if (response.errors) {
						alert(response.message);
					}
					
					/*
					if (response.found) {
						$("#autocreated").hide();
						$("#englishtext").text( "[" + response.baselanguage.toUpperCase() + "] "+response.data.translation);
						$("#translationkey").val(response.data.translationkey);
						$('#translation').val( ""  );
						$('#originaltranslation').val( ""  );
						
						
					} else {
						$("#englishtext").text('No '+ response.baselanguage.toUpperCase() +' translation found.');
						$('#translationkey').val( response.autokey  );
						// $("#select_namespace").val("template");
						$("#autocreated").show();
						$('#translationkey').focus();
					}
					main.enable("#btSaveTranslation");
					*/
				}
		});
	
}
