$(document).ready(function(){
	if($.browser.msie && $.browser.version < 9){
		$('#submenu, .submenu').css('overflow', 'visible');
		
		$('.button:has(.submenu)').each(function(){
			var div = $(this).find('.submenu').css({'top':'20px','height':'13px','background':'url(nix.gif)'}).hide();
			
			$(this).hover(function(){
				div.show();
				$('#submenu').hide();
			}, function(){
				div.hide();
				$('#submenu').show();
			});
		});
	}
	else{
		$('.button:has(.submenu)').each(function(){
			var div = $(this).find('.submenu').hide();
			
			$(this).hover(function(){
				div.stop().show().animate({'height':13, 'paddingTop':8}, 500);
				$('#submenu').stop().animate({'height':0}, 500);
			}, function(){
				div.stop().animate({'height':0, 'paddingTop':0}, 500, 'linear', function(){
					div.hide();
				});
				$('#submenu').stop().animate({'height':13}, 500);
			});
		});
	}
	
	function logos(obj, current, index){
		$('#home_dealers a')
			.removeClass('current')
			.eq(obj.find('> ul li:eq('+ (index -1)  +')').attr('rel') - 1)
				.addClass('current');
		$('#home_dealers_bar a')
			.removeClass('current')
			.eq(obj.find('> ul li:eq('+ (index -1)  +')').attr('rel') - 1)
				.addClass('current');
	}
	
	$('#slider').contentSlider({
		continues:true,
		pause:7,
		pauseAfterClick:false,
		afterSlide:logos
	});
	
	logos($('#slider'), 1, 1);
	
	$("select").msDropDown({'rowHeight':16});
	
	var models = {};
	$('#occasion_zoeken select[name=model] option').each(function(){
		var brand = $(this).attr('class').substr(6);
		
		if(!$.isArray(models[brand]))
			models[brand] = new Array();
		
		models[brand].push(new Array($(this).attr('value'), $(this).text()));
	});
	
	function filterModels(){
		var select = $('#occasion_zoeken select[name=model]');
		var length = select.find('option').length;
		var selectbox = $(select).msDropDown().data("dd");
		
		var selected = select.val();
		
		for(var i = 1; i < length; i++)
			selectbox.remove(1);
		
		if($.isArray(models[$('#occasion_zoeken select[name=brand]').val()])){
			for(var i = 0; i < models[$('#occasion_zoeken select[name=brand]').val()].length; i++){
				if(selected == models[$('#occasion_zoeken select[name=brand]').val()][i][0])
					var selectedIndex = i;
				
				selectbox.add({text:models[$('#occasion_zoeken select[name=brand]').val()][i][1],
					value:models[$('#occasion_zoeken select[name=brand]').val()][i][0]});
			}
			
			if(selectedIndex != undefined){
				selectbox.selectedIndex(selectedIndex + 1);
			}
		}
	}
	
	$('#occasion_zoeken select[name=brand]').bind('change', filterModels);
	if ($('#occasion_zoeken select[name=brand]').val() != ""){
		filterModels();
	}
	
	$("div.occasion_details div.images img.small").bind("mouseover", function(){
		$("div.occasion_details div.images img.big").attr("src", $(this).attr("src").replace("/thumb/", "/normal/"));
	});
	
	$("a[rel^='occassions']").prettyPhoto();
});

function MorePictures(val){
	$("a[rel^='occassions[" + val + "]']:first").click();
}

function showCategory(Id, Object){
	if ($("div#category_" + Id).is(":visible")){
		$("div#category_" + Id).hide();
		$(Object).addClass("shown");
	} else {
		$("div#category_" + Id).show();
		$(Object).removeClass("shown");
	};
}
