$(function(){
	
	if ($.browser.msie && $.browser.version < 7)
		$('img[src$=.png]').pngfix();

	$('img[data-hover],input[data-hover]').imghover();
	
	$('input.reset-default, textarea.reset-default').focus(function() {
        if(this.value == this.defaultValue) {
	        $(this).removeClass('reset-default');
	        this.value = '';
        }
    }).blur(function() {
        if($(this).attr('value').replace(/ +/, '') == '') {
	        $(this).addClass('reset-default');
            this.value = this.defaultValue;
        }
    }).parents('form').submit(function() {
        $('input.reset-default, textarea.reset-default', this).attr('value', '');
    });

	// Row syncs
	$('#contentwrapper').rowSync('div.halfcolumn', 2);
	$('#contentwrapper').rowSync('div.colsbg', 3, '.onethirdcolumn');
	$('#contentwrapper').rowSync('div.onethirdcolumn', 4, ['h2', 'ul', 'p.bttnsmall']);
	$('#footer').rowSync('ul>li', 3, 'span.title');
		

//When homepage loads... prepare tabs
	if( $(".client-tabs .tab_content").length > 0 ){
		$(".client-tabs .tab_content").hide().each(function(i, e){
            $(e).attr('id', '__' + $(e).attr('id'));
        }); 
		
		// tab switcher
		function switchTab(id){
			$(".client-tabs ul#tabs li").removeClass("active"); //Remove any "active" class
			$(".client-tabs ul#tabs li a[href$='" + id + "']").parent().addClass("active");
			$(".client-tabs .tab_content").hide(); //Hide all tab content

            $('a[href*="providers.search"]').not('.client-tabs ul#tabs li a').each(function(i, e){
                $(e).attr('href', $(e).attr('href').replace(/(#.*)?$/, id));
            });
	
//            window.location.hash = id;
			var activeTab = id.replace(/^\#/, '#__');
			if($.browser.msie){
				$(activeTab).show();
			}else{
				$(activeTab).fadeIn(); //Fade in the active ID content
			}
			return false;
		}

		//On Click Event
		$(".client-tabs ul#tabs li a").click(function(e) {
			var tabid = $(this).attr("href").replace(/^[^#]+/, '');
			switchTab(tabid);
            return false;
		});
		
		if(window.location.hash){
			switchTab(window.location.hash);
		}else{
			switchTab($("ul#tabs > li:first a").attr('href').replace(/^[^#]+/, '')); //Activate first tab
		}
	}
	
	// Hook up datepickers
	var months_long = ['januari', 'februari', 'maart', 'april', 'mei', 'juni', 'juli', 'augustus', 'september', 'oktober', 'november', 'december'];
	var months_short = ['jan', 'feb', 'mrt', 'apr', 'mei', 'jun', 'jul', 'aug', 'sep', 'okt', 'nov', 'dec'];
	var days_long = ['zondag', 'maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag'];
	var days_short = ['zon', 'maa', 'din', 'woe', 'don', 'vrij', 'zat'];
	var days_min = ['zo', 'ma', 'di', 'wo', 'do', 'vr', 'za'];


	$('input.datepicker').datepicker({
		dayNames: days_long,
		dayNamesMin: days_min,
		dayNamesShort: days_short,
		monthNames: months_long,
		monthNamesShort: months_short,
		showAnim: 'fadeIn',
		duration: 'fast',
		dateFormat: 'dd-mm-yy'
	});


// replace HR-tags with a DIV
	function replaceRulers() {
		$("hr").replaceWith('<div class="ruler"></div>');
	}
	
	if( ($(".sidecolumn div.block").length > 0) ){
		$(".sidecolumn div.block:last").css('margin','0');
	}

// initialize scrollable items
	$(".imagethumb .scrollable").scrollable({speed:500, circular: true, mousewheel: false}).navigator();
	$("#themesscroller .scrollable").scrollable({size:3, speed:500, circular: true, mousewheel: false}).navigator();
		
	// could be a solution for ending the scroll when the last item is visible.
	$("#themesscroller .scrollable").scrollable({
		onBeforeSeek: function(e, i) {
			$('.next').css('display', i>=this.getSize()-3 ? 'none' : 'block');			
		}
	});
	

// add odd-even rows to filterresults (providerpage)
	 $('div.filterresults dl dd ol').each(function() {
	 	$(this).find('li a').each(function(index){
			if(index % 2 == 0){ $(this).addClass('odd');}
		});
	 });
	 
	 
// toggle password-request form
	$("#pwrequest").click(function() {
		$('#passwordrequest').slideDown('slow');
		return false;
	});
	
	// zebra rows
	if( $('table.zebra').length > 0 ){
		$('table.zebra tr:odd').addClass('odd');
	}

    var fnToggleOtherLocation = function () {
        $('form.calendar-item fieldset#location_other').toggle($(this).val() == 'null');
    };
    $('form.calendar-item select#Location').each(fnToggleOtherLocation).change(fnToggleOtherLocation);

// check if stylesheets are loaded. If not, don't launch this jQuery stuff.
	if( $("div#cultkaart_logo a span").css("display") == 'none' ){
		 /* */
		 replaceRulers();
		 
		 // init suckerfish dropdown navigations
		 $('ul.sf-menu, .nav').superfish();
	}

    $('dl#filters dt a').click(function() {
        $(this).parent().toggleClass('active').next('dd:first').toggleClass('active');
        return false;
    });
});
