/* ------------------------------------------------- */
/* JQuery functions
/* ------------------------------------------------- */
var homepage = {
	items: null,
	init: function() {
		var hp = this;
		hp.items = $('#greep-uit-aanbod div.scrollable div.aanbod-item');
		hp.items.css({'cursor':'pointer'});
		hp.events();
		// Init external plugins
		$('#greep-uit-aanbod div.scrollable').scrollable({easing:'easeInOutQuad',circular:true,speed:1000}).autoscroll(5000);
	},
	events: function() {
		var hp = this;
		hp.items.click(function() {
			window.location = $('a', $(this)).attr('href');
		});
	}
}

var thumbsView = {
	items: null,
	init: function() {
		var th = this;
		th.items = $('#thumb-view li.thumb');
		th.items.css({'cursor':'pointer'});
		th.events();
	},
	events: function() {
		var th = this;
		th.items.bind('mouseenter', function() {
			$('h5.thumb-top', $(this)).stop().animate({'top':0}, 400);
			$('p.thumb-bottom', $(this)).stop().animate({'bottom':0}, 400);
			$('a.meer-info', $(this)).stop().fadeOut(100);
		});
		th.items.bind('mouseleave', function() {
			$('h5.thumb-top', $(this)).stop().animate({'top':-38}, 800);
			$('p.thumb-bottom', $(this)).stop().animate({'bottom':-65}, 800);
			$('a.meer-info', $(this)).stop().fadeIn(1000);
		});
		th.items.bind('click', function() {
			window.location = $('a', $(this)).attr('href');
		});
	}
}

var listView = {
	trs:null,
	init: function() {
		var lv = this;
		lv.trs = $('table tbody tr');
		lv.trs.css({'cursor':'pointer'});
		$('table tbody tr:even').addClass('alt');
		lv.events();
		// Init external plugins
		$('#list-table').tablesorter({headers:{0:{sorter:false},3:{sorter:false}}});
	},
	events: function() {
		var lv = this;
		lv.trs.bind('mouseenter', function() {
			$(this).addClass('hover');
		});
		lv.trs.bind('mouseleave', function() {
			$(this).removeClass('hover');
		});
		lv.trs.bind('click', function() {
			window.location = $('td.meer-info a', $(this)).attr('href');
		});
	}
}

var detailView = {
	items: null,
	inputs: null,
	init: function() {
		var dv = this;
		dv.inputs = $('form input, form textarea');
		dv.inputs.load(function() {
			if($(this).val() != '') $('label', $(this).parent()).not('.error').css({'text-align':'right','color':'#d0dbde'});
		});
		dv.events();
		// Init external plugins
		$('#detail-photos div.scrollable').scrollable({easing:'easeInOutQuad',circular:true,speed:1000}).autoscroll(5000);
		$('#info-aanvraag').validate({
                    submitHandler: function(form) {
                        jQuery(form).ajaxSubmit({
                            target: "#info-aanvraag"
                        });
                    }
                });
		$('#view-list-table').tablesorter({headers:{0:{sorter:false},2:{sorter:false}}});
	},
	events: function() {
		var dv = this;
		dv.inputs.bind('focus', function() {
			$('label', $(this).parent()).not('.error').css({'text-align':'right','color':'#d0dbde'});
		}),
		dv.inputs.bind('blur', function() {
			if($(this).val() == '') $('label', $(this).parent()).not('.error').css({'text-align':'left','color':'#374a52'});
		})
	}
}

var realisationsView = {
	items: null,
	init: function() {
		var th = this;
		th.items = $('#realisations-view li.thumb');
		th.items.css({'cursor':'pointer'});
		th.events();
		// Init external plugins
		$('a.colorbox').colorbox();
	},
	events: function() {
		var th = this;
		th.items.bind('mouseenter', function() {
			$('h5.thumb-top', $(this)).stop().animate({'top':0}, 400);
			$('p.thumb-bottom', $(this)).stop().animate({'bottom':0}, 400);
			$('a.meer-info', $(this)).stop().fadeOut(100);
		});
		th.items.bind('mouseleave', function() {
			$('h5.thumb-top', $(this)).stop().animate({'top':-38}, 800);
			$('p.thumb-bottom', $(this)).stop().animate({'bottom':-65}, 800);
			$('a.meer-info', $(this)).stop().fadeIn(1000);
		});
		th.items.bind('click', function() {
			$.colorbox({href:$('a', $(this)).attr('href'), rel:$('a', $(this)).attr('rel')});
		});
	}
}

/* ------------------------------------------------- */
/* On document ready
/* ------------------------------------------------- */
jQuery(document).ready(function($) {
	
	/* Homepage */
	homepage.init()
	/* Thumbs view */
	thumbsView.init();
	/* Tables view */
	listView.init();
	/* Detail view */
	detailView.init();
	/* Detail view */
	realisationsView.init();
	
	$('div.scrollpane').jScrollPane();
	$('#columnize').columnize({columns:2});
	
});

