$(function()
{
	
    $(".navigation li").hover(function(){
        
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    
    }, function(){
    
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    
    });
	
	$('[placeholder]').focus(function()
	{
		var input = $(this);
		if (input.val() == input.attr('placeholder'))
		{
			input.val('');
			input.removeClass('placeholder');
		}
	}).blur(function()
	{
		var input = $(this);
		if (input.val() == '' || input.val() == input.attr('placeholder'))
		{
			input.addClass('placeholder');
			input.val(input.attr('placeholder'));
		}
	}).blur();
	
	$('[placeholder]').parents('form').submit(function()
	{
		$(this).find('[placeholder]').each(function()
		{
			var input = $(this);
			if (input.val() == input.attr('placeholder'))
			{
				input.val('');
			}
		});
	});
	
	$('form').live('submit', function(event)
	{
		if (this.method != 'post')
		{
			return;
		}
		event.preventDefault();
		var form = $(this);
		form.find('.error').attr('original-title', '');
		form.find('.error').attr('title', '');
		form.find('.error').removeClass('error');
		form.find('fieldset').append('<div class="loader"></div>');
		form.find('input[type=submit]').attr('disabled', true);
		$.post(this.action, $(this).serialize(), function(data)
		{
			alert(data.message);
			if(data.return_value)
			{
				window.location.reload();
			}
			else
			{
				$.each(data, function(id, msgs)
				{
					$.each(msgs, function(type, msg)
					{
						if (typeof(msg) == 'object')
						{
							form.find('#'+type).addClass('error');
							$.each(msg, function (type_2, msg_2)
							{
								form.find('#'+type).attr('title',msg_2);
							});
						}
						else
						{
							form.find('#'+id).addClass('error');
							$.each(msgs, function (type_2, msg_2)
							{
								form.find('#'+id).attr('title',msg_2);
							});
						}
					});
					form.find('.error').tipsy({gravity:'w',fade:true,live:true});
				});
			}
			form.find('input[type=submit]').removeAttr('disabled');
			form.find('.loader').remove();
		}, 'json');
	});
	
    $('a[href$=\'.jpg\'], a[href$=\'.png\']').live('click',function(event)
    {
        $.fancybox({
    		'href'			: this.href
    	});
        event.preventDefault();
    });
    
    $('.offer-button').live('click', function()
	{
    	$('.offer-button').toggle(function()
    	{
        	$(".content-wrapper").animate({"marginTop": "+="+$('.offer-wrapper').height()+"px"}, 200);
        	$(".offer-wrapper").show();
    	},function()
    	{
    		$(".content-wrapper").animate({"marginTop": "-="+$('.offer-wrapper').height()+"px"}, 200);
    		$(".offer-wrapper").hide();
    	}).trigger('click');
	});
	
});

function woopraReady(tracker) {
    tracker.setDomain('squareconcepts.nl');
    tracker.setIdleTimeout(60000);
    tracker.trackPageview({type:'pageview',url:window.location.pathname+window.location.search,title:document.title});
    return false;
}
(function() {
    var wsc = document.createElement('script');
    wsc.src = document.location.protocol+'//static.woopra.com/js/woopra.js';
    wsc.type = 'text/javascript';
    wsc.async = true;
    var ssc = document.getElementsByTagName('script')[0];
    ssc.parentNode.insertBefore(wsc, ssc);
})();
