/*mogelijke TODO (wanneer er tijd voor is, niet implementeren is niet erg):
-Blokkeren toevoegen IPTC_code die direct of indirect al een child heeft welke al toegevoegd is.
-Errormelding bij toevoegen IPTC wat niet mag
*/

var current_menu = 1;
var klaar = 1;
var autoArray;
var mediaGegevens;
var toegevoegde_IPTC_id = 1;
var gekozen_IPTC_codes = Array();
var fout = Array();
var arrayId = "";

function showCar(autoId) {
	//laadGegevens(autoId);
	openPopUp(autoId);
}

function laadGegevens(autoId) {
	var hashValues = new Hash();
    hashValues.set('id', autoId);
    new Ajax.Request('auto_info_ophalen.php',
		{
		    method: 'post', parameters: hashValues,
		    onSuccess: function(transport) {
		        var response = transport.responseText || "";
		        jsonData = eval('(' + response + ')');
		        autoArray = jsonData;
		    },
		    onFailure: function() { alert('Er ging iets mis...') }
		});
}

//deze code zorgt voor het in en uitklappen van de stappen
function uitklappen(menu) {
    if (current_menu != menu && klaar == 1) {
        klaar = 0;
        new Effect.BlindUp('gegevens' + current_menu, { duration: 0.5 });
        new Effect.BlindDown('gegevens' + menu, { afterFinish: readyCheck, duration: 0.5 });
        current_menu = menu;
    }
}

function slideToggle(menu) {    
	var menu = "div_" + menu;
	new Effect.toggle(menu.toString(), 'blind', { duration: 0.5 });
}

function shake(menu) {
	var menu = "div_" + menu;
	new Effect.Shake(menu.toString(), { duration: 0.5 });
}

function checkboxAan(iptc_code) {
	var checkbox_naam = iptc_code + "_checkbox";
	document.getElementsByName(checkbox_naam)[0].checked = true;
}

function checkboxUit(iptc_code) {
	var checkbox_naam = iptc_code + "_checkbox";
	document.getElementsByName(checkbox_naam)[0].checked = false;
}


function openPopUp(autoId) {
	var iptc_parent;
	var iptc_naam;
	var iptc_code_sub;
	var tekst_inhoud = "";
	
	
        for (var p = 0; p < autoArray.length; p++) {

			if (autoArray[p]['autoid'] == autoId) {
				arrayId = p;
			}
		}
	
	document.getElementById("message_title").innerHTML = autoArray[arrayId]['merk'] + " " + autoArray[arrayId]['model'] + " " + autoArray[arrayId]['uitvoering'];
	
	document.getElementById("merk").innerHTML = autoArray[arrayId]['merk'];
	document.getElementById("model").innerHTML = autoArray[arrayId]['model'];
	document.getElementById("uitvoering").innerHTML = autoArray[arrayId]['uitvoering'];
	
	document.getElementById("kleur").innerHTML = autoArray[arrayId]['kleur'];
	document.getElementById("brandstof").innerHTML = autoArray[arrayId]['brandstof'];
	document.getElementById("bouwjaar").innerHTML = autoArray[arrayId]['bouwjaar'];
	document.getElementById("vermogen").innerHTML = autoArray[arrayId]['vermogen'] + " kW";
	
	document.getElementById("tekst_1").innerHTML = autoArray[arrayId]['tekst_1'];
	document.getElementById("tekst_2").innerHTML = autoArray[arrayId]['tekst_2'];

	document.getElementById("transmissie").innerHTML = autoArray[arrayId]['transmissie'];
	document.getElementById("carrosserievorm").innerHTML = autoArray[arrayId]['carrosserievorm'];
	document.getElementById("kilometerstand").innerHTML = autoArray[arrayId]['kilometerstand'] + " km";
	
	document.getElementById("showroomvraagprijs").innerHTML = "&euro; " + autoArray[arrayId]['showroomvraagprijs'];
	document.getElementById("gewicht").innerHTML = autoArray[arrayId]['gewicht'] + " kg";
	document.getElementById("cilinderinhoud").innerHTML = autoArray[arrayId]['cilinderinhoud'] + " cc";


	document.getElementById("foto_1b").innerHTML = autoArray[arrayId]['foto_1b'];
	
	document.getElementById("foto_1").innerHTML = autoArray[arrayId]['foto_1'];
	document.getElementById("foto_2").innerHTML = autoArray[arrayId]['foto_2'];
	document.getElementById("foto_3").innerHTML = autoArray[arrayId]['foto_3'];
	document.getElementById("foto_4").innerHTML = autoArray[arrayId]['foto_4'];
	document.getElementById("foto_5").innerHTML = autoArray[arrayId]['foto_5'];
	document.getElementById("foto_6").innerHTML = autoArray[arrayId]['foto_6'];
	document.getElementById("foto_7").innerHTML = autoArray[arrayId]['foto_7'];
	document.getElementById("foto_8").innerHTML = autoArray[arrayId]['foto_8'];
	
	document.getElementById("opties").innerHTML = autoArray[arrayId]['opties'];
	
	document.getElementById("message_block").style.width = "878px";
	//document.getElementById("message_block").style.height = "200px";

	new Effect.toggle("background_overlay", 'Appear', { duration: 0.5 });
	new Effect.toggle("message_background", 'Appear', { duration: 0.5 });
	new Effect.Appear("message_block", {  });
}

function openPhoto(photoId) {
	//alert(photoId);
	document.getElementById("foto_1b").innerHTML = "<a href=\"" + photoId + "\" rel=\"lightbox\"><img style=\"margin: 9px; margin-bottom: 0px;\" width=\"325\" height=\"243\" src=\"" + photoId + "\" alt=\"\" /></a>";

}


function openPhotoAutoVak(photoId, id) {
	//alert(photoId);
	
	var elementId = "foto_1b_" + id;
	document.getElementById(elementId).innerHTML = "<a href=\"" + photoId + "\" rel=\"lightbox\"><img style=\"margin-left: 12px; margin-top: 4px;\" width=\"163\" height=\"122\" src=\"" + photoId + "\" alt=\"\" /></a>";

}


function berichtOpenen(kop, tekst) {
	document.getElementById("message_title").innerHTML = kop;
	document.getElementById("message_text").innerHTML = tekst;
	
	document.getElementById("message_block").style.width = "360px";
	document.getElementById("message_block").style.height = "150px";

	new Effect.toggle("background_overlay", 'Appear', { duration: 0.5 });
	new Effect.toggle("message_background", 'Appear', { duration: 0.5 });
	new Effect.Appear("message_block", {  });
	new Effect.Shake("message_block", { duration: 0.3 });
}

function berichtSluiten() {
	new Effect.DropOut("message_block", {  });
	new Effect.toggle("message_background", 'Appear', { duration: 0.5 });
	new Effect.toggle("background_overlay", 'Appear', { duration: 0.5 });
}

function readyCheck() {
klaar = 1;
}