// JavaScript Document main LeasePlan Occasions 2011

var formname;
var fullHeight;

$(document).ready(function(){
	if($('#slider-code').length != 0) {
		$('#slider-code').tinycarousel({
			display : 3,
			duration: 400
		});
	}
	
	if($('#repairs').length != 0) {
		fullHeight = $('#repairs').height();
		$('#repairs').height(150);
	}
	
	//SET ACTIVE MENU CASS
    //WJ 25-10-2010
	if(typeof(activepage) != 'undefined') { 
	    var m_item = jQuery('.menuskin li:nth-child(' + activepage + ')');
	    m_item.addClass('active');
				
	}
	
});

//OPEEN CLOSE HISTORY
function showAll() {
	var currHeight = $('#repairs').height();
	if(currHeight == 150) {
		$('#repairs').animate({
				height : fullHeight
			}, 500, function() {
				$('#more').html("minder");
			}
		);
	} else {
		$('#repairs').animate({
				height : 150
		}, 500, function() {
			$('#more').html("meer");
		}
		);
	}
}

// DETAIL scripts
function goDetail(dir) {
	var sid; 
	if(dir == -1) {
		if(curCar > 0) {
			sid = sids[curCar-1];
			detail_form.curIndex.value = curCar-1;
			detail_form.sid.value      = sid;
			detail_form.submit();
		}
	} else {
		if(curCar < sids.length-1) {
			sid = sids[curCar+1];
			detail_form.curIndex.value = curCar+1;
			detail_form.sid.value      = sid;
			detail_form.submit();
		}
	}
}

function formatNumber(type, str) {
	var nr = "";
	if(type == "cur") {
		tmpArr = str.split(".");
		_str   = tmpArr[0].toString();
		nr     = _str.substr(0, _str.length-3) + "." + _str.substr(_str.length-3, _str.length);
	}
	if(type == "mile") {
		_str   = String(str);
		nr     = _str.substr(0, _str.length-3) + "." + _str.substr(_str.length-3, _str.length);
	}
	return nr;
}

function sendCar(ref) {
	var str     = "toolbar=no,status=no,menubar=no,location=no,scrollbars=yes,resizable=yes,height=320,width=500"
	var dataURL = "http://www.leaseplan.nl/occasions/detail-gevonden-occasion.asp?sid=" + ref;
	var url     = "tell_a_friend.asp?page=" + dataURL;
	tellaFriend = window.open(url, "TellObj", str);
    tellaFriend.opener = top;
}

function loadPreview(nr) {
	$(".mainimg").attr('rel', nr);
	$(".mainimg").attr('src', imgArray[parseInt(nr)]);
}

function popImg() {
	nr = parseInt($(".mainimg").attr('rel'));
	jQuery.slimbox(imgArray, nr, {overlayOpacity       : 0.6,
								  overlayFadeDuration  : 300,
								  resizeDuration       : 300,
								  counterText          : "Foto {x} van {y}",
								  closeKeys            : [27, 67],
								  nextKeys             : [79, 86],
								  loop                 : true}
	);
}

function showZoom(flag) {
	if (flag == "1") {
		$(".zoombtn").show();
	} else {
		$(".zoombtn").hide();
	}
	
}

