﻿jQuery.fn.infoPopup = function(oParams) {
	var text 	= $(this).attr("title");

	if(oParams.pos == "L"){
		var div		= $("div.popup_infoL[@rel="+oParams.type+"]");
	} else {
		var div		= $("div.popup_info[@rel="+oParams.type+"]");
	}

	var cDiv	= div.find("div");
	var item	= $(this);
	var typeID	= oParams.typeID;

	item.removeAttr("title");

	item.hover(function() {
		cDiv.html(text);
		div.appendTo(item.parent());
		div.show();
	}, function() {
		div.hide();
		div.insertBefore($("#"+typeID));
	});
};

jQuery.fn.extend({

	initInfoPopups: function(pos) {
		if(!pos){
			pos="";
		}

		var thumbs 	= $(this).find("label.error img");
		var type	= $(this).attr("id")+"Display";
		var typeID	= $(this).attr("id");
		thumbs.each( function(i) {
			if($(this).attr("title")){
				$(this).infoPopup({"type":type,"typeID":typeID,"pos":pos});
			}
		});
	}

});

function submitFeedback()
{
	$('#feedback_form').hide();
	$('#feedback_error').hide();
	$('#feedback_loader').show();

	var naam = ( $('#feedbackNaam').val() == $('#feedbackNaam').data("defText") ? '' : $('#feedbackNaam').val() );
	var email = ( $('#feedbackEmail').val() == $('#feedbackEmail').data("defText") ? '' : $('#feedbackEmail').val() );
	var message = ( $('#feedbackBericht').val() == $('#feedbackBericht').data("defText") ? '' : $('#feedbackBericht').val() );

	$.ajax({
		type: "POST",
		url: '/contact/ajax/processform.php',
		data: ({
			ys_language: ys_language,
			ys_site: ys_site,
			naam: naam,
			email: email,
			message: message,
			type: 'feedback'
		}),
		dataType: 'json',
		success: function( json ) {
			if( json.error )
			{
				$('#feedback_form').show();
				$('#feedback_loader').hide();
				$('#feedback_error').html(json.error).show();
			}
			else
			{
				$('#feedback_loader').html( YM_trans('Bericht verzonden') );
			}
		}
	});
}

$(document).ready(function() {

	$('#btnFeedback').click( function (){
		submitFeedback();
	});

	$('img[src$=".png"]').ifixpng();
	$('input[type="radio"]').ezMark();

	if (typeof jQuery.fn.jdMenu == 'function') {
		$('ul.sitemenu').jdMenu({
			disableLinks: false
		});
	}

	//feedback
	$('div#feedback_button').toggle(
		function(){
			$('div#overlay').show().height( $(document).height() );
			$('div#feedback').show().animate(
				{
					left: "43px"
				},
				{
					duration: 400,
					queue: false
				}
			);
		},
		function(){
			$('div#feedback').animate(
				{
					left: "-960px"
				},
				{
					duration: 400,
					queue: false,
					complete: function() {
						$(this).hide()
						$('div#overlay').hide();
					}
				}
			);
		}
	);
	$('#feedback_close, #overlay').click( function() {
		$('div#feedback_button').trigger('click');
	});

	//toggle leftmenu
	$('#header_menu_left span[rel]').hover(
		function () {
			$(this).addClass("strong");
			var tooltipId = $(this).attr('rel');
			$('div#' + tooltipId).stop(true, true).fadeIn('fast');
		},
		function () {
			$(this).removeClass("strong");
			var tooltipId = $(this).attr('rel');
			$('div#' + tooltipId).stop(true, true).fadeOut('fast');
		}
	);

	//toggleval
	$(".toggleInput").toggleVal({
		populateFrom:	"labelAndEmpty",
		removeLabels:	true,
		focusClass:		"hasFocus",
		changedClass:	"isChanged"
	});

	//quick search
	$("form#searchContent, form#loginForm").submit(function(){
		$(this).find(".toggleInput").each(function() {
			if($(this).val() == $(this).data("defText")) {
				$(this).val("");
			}
		});
	});

	if( $("#carousel").length > 0 )
	{
		$("#carousel").jCarouselLite({
			btnNext: "#footer_nav_right",
			btnPrev: "#footer_nav_left",
			visible: 3,
			scroll: 3,
			circular: false
		});
	}
});
