/*
 *
 * Textarea Maxlength Setter JQuery Plugin
 * Version 1.0
 *
 * Copyright (c) 2008 Viral Patel
 * website : http://viralpatel.net/blogs
 *
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
*/

$(document).ready(function () {
	$(".buttonGrey,.buttonBlack").hover(function () { $(this).addClass("hover");},function () { $(this).removeClass("hover");});
	$(".topButtonRow li").append($("<span />").addClass("activeArrow").html("&nbsp;"));
	$(".activeArrow").each(function () {
		btnWidth = Math.floor(($(this).prev("a").outerWidth()-10)/2);
		$(this).css({ left: btnWidth});
	});	

	$(".extraInfoPanel").append($("<span />").addClass("activeArrow").html("&nbsp;"));
	//$(".topPanelTwirls").wrapInner($("<div/>").addClass("bgTwirls"));
	//$(".whitePanel").prepend($("<div/>").html("&nbsp;").addClass("whitePanelTop"));
//	$(".topPanelTwirls").prepend($("<div/>").html("&nbsp;").addClass("bgTwirls"));
	//$(".whitePanel").append($("<div/>").html("&nbsp;").addClass("whitePanelBottom"));


	$(".diaryDateValue").datepicker({
	    showOn: 'both',
	    dateFormat: 'dd-mm-yy',
	    buttonImage: '../doel/img/icon_calendar.gif',
	    buttonImageOnly: true,
	    dayNames: ['Zondag', 'Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag'],
	    dayNamesMin: ['Zo', 'Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za'],
	    monthNames: ['Januari', 'Februari', 'Maart', 'April', 'Mei', 'Juni', 'Juli', 'Augustus', 'September', 'Oktober', 'November', 'December']
	});
	
	$(".diaryRatingValue").
		after($("<div />").
				addClass("diaryRatingSlider").
				slider({ 
					   min:0,
					   max: 20,
						slide: function(event, ui) {
							$(".diaryRatingValue").val(ui.value);
							$(".diaryRatingValueLabel").html((ui.value/2));
						},
						value: $(".diaryRatingValue").val()

					   }));
		
	$(".diaryRatingSlider").after($("<div />").addClass("diaryRatingValueLabel").html(($(".diaryRatingValue").val() / 2)+"&nbsp;"));
	
	$(".giveSupport a.giveSupportLabel").bind("click",function() {
		isOpen = false;
		if($(this).hasClass("open")) { isOpen = true; }
		$(this).parents(".giveSupport").find("a.giveSupportLabel").removeClass("open");
		$(this).parents(".giveSupport").find(".giveSupportControl").fadeOut();
		if(isOpen==false)
		{
			$(this).next(".giveSupportControl").slideDown();
			$(this).addClass("open");
			$(this).parents(".giveSupport").animate({ "margin-bottom":51},function (){ $(".whitePanelBottom").hide().show();} );
			
		}
		else {
			$(this).parents(".giveSupport").animate({ "margin-bottom":0},function (){ $(".whitePanelBottom").hide().show();});
		}
		return false;
	});
	
	$(".writeMessage textarea").bind("focus",function () {
		if(!$(this).hasClass("open")){
		    $(this).animate({ height: 40}, 0, function(){$(this).addClass("open");});
    		$(this).parents(".writeMessage").find(".writeMessageMore").slideDown(function (){ $(".whitePanelBottom").hide().show();});
		};
													   
	});
	
    $('body').click(function() { 
        if($(".writeMessage textarea").hasClass("open")) {	
            $(".writeMessage textarea").animate({height: 16}); $(".writeMessage textarea").removeClass("open")
            $(".writeMessage textarea").parents(".writeMessage").find(".writeMessageMore").slideUp(function (){ $(".whitePanelBottom").hide().show();});
        };
    });	
    
    $('.writeMessage').click(function(event){ 
        event.stopPropagation(); 
    }); 
});
