function addToWishlist(productId) {
	var cookieName = 'wpan_wishlist';
	var expiresAfter = 10;
	var separator = ',';
	var currentCookie = $.cookie(cookieName);
	if(currentCookie == null) {
		currentCookie = '';
	}
	currentCookieArr = currentCookie.split(separator);

	if(currentCookie != '') {		
		for(var i=0; i<currentCookieArr.length; i++) {
			if(currentCookieArr[i] == productId) {
				showMessage("<strong>Attentie:</strong> U heeft dit product al aan uw offerte-aanvraag toegevoegd. <a href=\"http://bedruktetshirts.nl/uw-offerte-aanvraag/\">Ga naar uw offerte-aanvraag.</a>", "notification");
				return;
			}
		}
	}
	
	$.cookie(cookieName, currentCookie + (currentCookie != '' ? ',' : '') + productId, { path: '/', expires: expiresAfter });
	$('#wishlist-counter').html(parseInt($('#wishlist-counter').html()) + 1);
	
	showMessage("Het product is toegevoegd aan uw offerte-aanvraag. <a href=\"http://bedruktetshirts.nl/uw-offerte-aanvraag/\">Ga naar uw offerte-aanvraag.</a>", "");
	
	return;
}

function removeFromWishlist(productId) {
	var speed = "normal";
	var cookieName = 'wpan_wishlist';
	
	//jConfirm('Weet u zeker dat u het item van de offerte-aanvraag wilt verwijderen', '', function(r) {
	//	if(r == 'true' || r == true) {
			removeItemFromCookie(cookieName, productId);

			$('#wishlist-section-' + productId).slideUp(speed, function() {
				$(this).remove();
			});

			$('#wishlist-counter').html(parseInt($('#wishlist-counter').html()) - 1);
			showMessage("Het product is weggehaald van uw offerte-aanvraag", "");
	//	}
	//});
}

function clearWishlist() {
	jConfirm('Weet u zeker dat u deze lijst wilt leegmaken?', '', function(r) {
		if(r == 'true' || r == true) {
			$('#wishlist section.overview').fadeOut("normal");
			$.cookie('wpan_wishlist', null,  {path: '/', expires: -10 });
			$('#wishlist-counter').html("0");
			
			showMessage("De offerte-aanvraag is leeg gemaakt", "notification");
			window.setTimeout('location.reload()', 1000);
		}
	});
}

function removeItemFromCookie(cookieName, item) {
	var expiresAfter = 7;
	var separator = ',';
	var currentCookie = $.cookie(cookieName);
	if(currentCookie == null) {
		currentCookie = '';
	}
	currentCookieArr = currentCookie.split(separator);
	
	var i = 0;
	
	while(i < currentCookieArr.length) {
		if(currentCookieArr[i] == item) {
			currentCookieArr.splice(i, 1);
		}
		else {
			i++;
		}
	}
	currentCookie = currentCookieArr.join(separator);
	$.cookie(cookieName, currentCookie, { path: '/', expires: expiresAfter });
}

function showMessage(msg, type) {
	$.alerts.draggable = false;
	$.alerts.okButton = '';
	$.alerts.overlayOpacity = 0;
	$.alerts.showClose = true;
	$.alerts.preventHide = false;
	$.alerts.closeText = "Sluit opmerking";
	
	jAlert(msg, type);
}

(function($) {
	
	$.alerts = {
		
		// These properties can be read/written by accessing $.alerts.propertyName from your scripts at any time
		
		verticalOffset: -75,                // vertical offset of the dialog from center screen, in pixels
		horizontalOffset: 0,                // horizontal offset of the dialog from center screen, in pixels/
		repositionOnResize: true,           // re-centers the dialog on window resize
		overlayOpacity: .01,                // transparency level of overlay
		overlayColor: '#FFF',               // base color of overlay
		draggable: true,                    // make the dialogs draggable (requires UI Draggables plugin)
		okButton: 'OK',         			// text for the OK button
		cancelButton: 'Annuleren', 			// text for the Cancel button
		dialogClass: null,                  // if specified, this class will be applied to all dialogs
		hideTimeout: 4000, 					// number of miliseconds before dialog disappears
		preventHide: true,					// Prevent the automatic hide of the dialog
		showClose: false, 					// Show close link
		closeText: 'x',						// Close text
		// Public methods
		
		alert: function(message, type, title, callback) {
			$.alerts._show(title, message, type, null, 'alert', function(result) {
				if( callback ) callback(result);
			});
		},
		
		confirm: function(message, title, callback) {
			$.alerts._show(title, message, 'notification', null, 'confirm', function(result) {
				if( callback ) callback(result);
			});
		},
			
		prompt: function(message, value, title, callback) {
			$.alerts._show(title, message, 'notification', value, 'prompt', function(result) {
				if( callback ) callback(result);
			});
		},
		
		// Private methods
		
		_show: function(title, msg, messageType, value, type, callback, showClose, closeText) {
			$.alerts._hide();
			$.alerts._overlay('show');
			$("BODY").append(
			  '<div id="popup_container">' +
				( $.alerts.showClose ? '<a href="javascript:;" class="close-popup" id="popup_close_btn">' + $.alerts.closeText + '</a>' : '' ) +
				( title != '' ? '<h1 id="popup_title"></h1>' : '' ) + 
			    '<div id="popup_content">' +
			      '<p id="popup_message"></p>' +
				'</div>' +
			  '</div>');
			
			$('#popup_container').fadeIn("normal");
			
			if( $.alerts.dialogClass ) $("#popup_container").addClass($.alerts.dialogClass);
			
			if($.alerts.showClose) {
				$("#popup_close_btn").click(function() {
					$.alerts._hide();
				});
			}
			
			// IE6 Fix
			var pos = ($.browser.msie && parseInt($.browser.version) <= 6 ) ? 'absolute' : 'fixed'; 
			
			$("#popup_container").css({
				position: pos,
				zIndex: 99999
			});
			
			$("#popup_title").text(title);
			$("#popup_message").addClass(messageType);
			$("#popup_message").text(msg);
			$("#popup_message").html( $("#popup_message").text().replace(/\n/g, '<br />') );
			
			$("#popup_container").css({
				minWidth: $("#popup_container").outerWidth(),
				maxWidth: $("#popup_container").outerWidth()
			});
			
			$.alerts._reposition();
			$.alerts._maintainPosition(true);
						
			switch( type ) {
				case 'alert':
					if($.alerts.okButton != '') {
						$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /></div>');
					}
					$("#popup_ok").click( function() {
						$.alerts._hide();
						callback(true);
					});

					$("#popup_ok").focus().keypress( function(e) {
						if( e.keyCode == 13 || e.keyCode == 27 ) $("#popup_ok").trigger('click');
					});
				break;
				case 'confirm':
					$.alerts.okButton = 'OK';
					$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');
					$("#popup_ok").click( function() {
						$.alerts._hide();
						if( callback ) callback(true);
					});
					$("#popup_cancel").click( function() {
						$.alerts._hide();
						if( callback ) callback(false);
					});
					$("#popup_ok").focus();
					$("#popup_ok, #popup_cancel").keypress( function(e) {
						if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
						if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
					});
				break;
				case 'prompt':
					$("#popup_message").append('<br /><input type="text" size="30" id="popup_prompt" />').after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');
					$("#popup_prompt").width( $("#popup_message").width() );
					$("#popup_ok").click( function() {
						var val = $("#popup_prompt").val();
						$.alerts._hide();
						if( callback ) callback( val );
					});
					$("#popup_cancel").click( function() {
						$.alerts._hide();
						if( callback ) callback( null );
					});
					$("#popup_prompt, #popup_ok, #popup_cancel").keypress( function(e) {
						if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
						if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
					});
					if( value ) $("#popup_prompt").val(value);
					$("#popup_prompt").focus().select();
				break;
			}
			
			// Make draggable
			if( $.alerts.draggable ) {
				try {
					$("#popup_container").draggable({ handle: $("#popup_title") });
					$("#popup_title").css({ cursor: 'move' });
				} catch(e) { /* requires jQuery UI draggables */ }
			}
			
			if(!$.alerts.preventHide) {
				setTimeout('$.alerts._hide()', $.alerts.hideTimeout);
			}
		},
		
		_hide: function() {
			$("#popup_container").fadeOut("normal", function() {
				$(this).remove();
				$.alerts._overlay('hide');
				$.alerts._maintainPosition(false);
			});
			
		},
		
		_overlay: function(status) {
			switch( status ) {
				case 'show':
					$.alerts._overlay('hide');
					$("BODY").append('<div id="popup_overlay"></div>');
					$("#popup_overlay").css({
						position: 'absolute',
						zIndex: 99998,
						top: '0px',
						left: '0px',
						width: '100%',
						height: $(document).height(),
						background: $.alerts.overlayColor,
						opacity: $.alerts.overlayOpacity
					});
					
				break;
				case 'hide':
					$("#popup_overlay").remove();
				break;
			}
		},
		
		_reposition: function() {
			var top = (($(window).height() / 2) - ($("#popup_container").outerHeight() / 2)) + $.alerts.verticalOffset;
			var left = (($(window).width() / 2) - ($("#popup_container").outerWidth() / 2)) + $.alerts.horizontalOffset;
			if( top < 0 ) top = 0;
			if( left < 0 ) left = 0;
			
			// IE6 fix
			if( $.browser.msie && parseInt($.browser.version) <= 6 ) top = top + $(window).scrollTop();
			
			$("#popup_container").css({
				top: top + 'px',
				left: left + 'px'
			});
			$("#popup_overlay").height( $(document).height() );
		},
		
		_maintainPosition: function(status) {
			if( $.alerts.repositionOnResize ) {
				switch(status) {
					case true:
						$(window).bind('resize', $.alerts._reposition);
					break;
					case false:
						$(window).unbind('resize', $.alerts._reposition);
					break;
				}
			}
		}
		
	}
	
	// Shortuct functions
	jAlert = function(message, type, title, callback) {
		$.alerts.alert(message, type, title, callback);
	}
	
	jConfirm = function(message, title, callback) {
		$.alerts.confirm(message, title, callback);
	};
		
	jPrompt = function(message, value, title, callback) {
		$.alerts.prompt(message, value, title, callback);
	};
	
})(jQuery);

/**
 * jQuery cookies from http://plugins.jquery.com/project/Cookie
 */
jQuery.cookie = function(name, value, options) {
	
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

/* 
Simple JQuery menu.
HTML structure to use:

Notes: 

Each menu MUST have a class 'menu' set. If the menu doesn't have this, the JS won't make it dynamic
If you want a panel to be expanded at page load, give the containing LI element the classname 'expand'.
Use this to set the right state in your page (generation) code.

Optional extra classnames for the UL element that holds an accordion:

noaccordion : no accordion functionality
collapsible : menu works like an accordion but can be fully collapsed

<ul class="menu [optional class] [optional class]">
<li><a href="#">Sub menu heading</a>
<ul>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
...
...
</ul>
// This item is open at page load time
<li class="expand"><a href="#">Sub menu heading</a>
<ul>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
...
...
</ul>
...
...
</ul>

Copyright 2007-2010 by Marco van Hylckama Vlieg

web: http://www.i-marco.nl/weblog/
email: marco@i-marco.nl

Free to use any way you like.
*/


jQuery.fn.initMenu = function() {  
    return this.each(function(){
        var theMenu = $(this).get(0);
        $('.acitem', this).hide();	
        $('li.expand > .acitem', this).prev().addClass('active');
		$('li.expand > .acitem').show();
		$('.current-cat', this).addClass('open');
		$('li.open').parent().show();
        $('li a', this).click(
            function(e) {
                e.stopImmediatePropagation();
                var theElement = $(this).next();
                var parent = this.parentNode.parentNode;
                if($(parent).hasClass('noaccordion')) {
                    if(theElement[0] === undefined) {
                        window.location.href = this.href;
                    }
                    $(theElement).slideToggle('normal', function() {
                        if ($(this).is(':visible')) {
                            $(this).prev().addClass('active');
                        }
                        else {
                            $(this).prev().removeClass('active');
                        }    
                    });
                    return false;
                }
                else {
                    if(theElement.hasClass('acitem') && theElement.is(':visible')) {
                        if($(parent).hasClass('collapsible')) {
                            $('.acitem:visible', parent).first().slideUp('normal', 
                            function() {
                                $(this).prev().removeClass('active');
                            }
                        );
                        return false;  
                    }
                    return false;
                }
                if(theElement.hasClass('acitem') && !theElement.is(':visible')) {         
                    $('.acitem:visible', parent).first().slideUp('normal', function() {
                        $(this).prev().removeClass('active');
                    });
                    theElement.slideDown('normal', function() {
                        $(this).prev().addClass('active');
                    });
                    return false;
                }
				
            }
        }
    );
});
};

$(document).ready(function() {$('.menu').initMenu();});


