/* SET VARIABLES */
var map;
var mapMarkers = [];
var mapHTMLS = [];
var openInfowindow;
var bounds;

/* DOC READY */
$(document).ready(function(){

	/* COMMON INIT */
	initCommon();
	
	/* PAGE DEPENDENT */
	switch(pagedata.name)
	{
		case 'home':
			initHome();
			break;
		case 'locations':
			initLocations();
			break;
		case 'evs':
			initLocations();
			initEvs();
			break;
		case 'contact':
			initContact();
			break;
		case 'membership':
			initMembership();
			break;	
	}

});

$(window).load(function(){
	if(login_error!='')
		alert(login_error);
});


initCommon = function()
{
	/* INIT MENU HIDE */
	$('#menu ul li ul').hide();
	$('#menu ul li.open ul').show();

	$('#menu ul li a').click(toggleMenu);

	/* AUTO LABELS FOR CONTACTFORM */
	$('#login form label').inFieldLabels({ fadeOpacity:0 });
	$('#search form label').inFieldLabels({ fadeOpacity:0 });
	
	/* AUTO LABELS FOR ADDFORM */
	$('#content .addpoint form label').inFieldLabels({ fadeOpacity:0 });
}

initHome = function()
{
	/* CALL ROTATOR */
	theRotator();
}

initLocations = function()
{
	if(typeof locations=="undefined")
		return;
		
	if(locations.length){
		loadMap();
	
		/* CHECK FOR CLICKED SIDEBAR LOCATION */
		if (is_search){
			$('#sidebar li a.marker').click(function(){
				var id = parseInt($(this).parent().attr('id').replace('location_',''))
				markerClicked(id);
				
				/* GET MORE CONTAINER */
				moreContainer = $(this).siblings('.more');
				
				/* CHECK IF CURRENT INFO IS VISIBLE */
				if (moreContainer.not(':visible')){
					/* SLIDE UP VISIBLE CONTAINER */
					$('.location .more:visible').slideUp();
				}
				
				/* RETURN FALSE */
				return false;
			});
		}
	}
	
	if (is_search){
		/* BIND CLICK TO MORE INFO TOGGLE */
		$('.location a.toggle').click(function(){
		
			/* GET MORE CONTAINER */
			moreContainer = $(this).siblings('.more');
			
			/* CHECK IF MORE CONTAINER EXISTS */
			if (moreContainer.length!=0)
			{
				/* CHECK IF CURRENT INFO IS VISIBLE */
				if (moreContainer.is(':visible')){
				
					/* SLIDE UP */
					moreContainer.slideUp();
					
					/* TOGGLE ARROW */
					$(this).removeClass('open');
				} else {
					/* CHECK IF CURRENT INFO IS INVISIBLE */
					if (!moreContainer.is(':visible')){
					
						/* SLIDE UP VISIBLE CONTAINER */
						$('.location .more:visible').slideUp();
						
						/* TOGGLE ARROW */
						$('.location .toggle.open').removeClass('open');
					}
					
					/* SLIDE DOWN CURRENT CONTAINER */
					moreContainer.slideDown();
					
					/* TOGGLE ARROW */
					$(this).addClass('open');
				}
			}
			
			/* RETURN FALSE */
			return false;
		});
	}
	
	if (!is_search){
		/* HIDE CONTENT */
		$('.addpoint .content').hide();
		
		/* CLICK ON ADD BUTTON */
		if(pagedata.name=='locations')
			$('.addpoint .addbutton').click(addPoint);
		
		/* VALIDATIONS */
		$(".addpoint form").validate({
			focusInvalid: false,
			/* RULES */
			rules: {
				persoon: "required",
				email: {
					required: true,
					email:true
				},
				naam: "required",
				adres: "required",
				postcode: "required",
				gemeente: "required",
				photo: {
					accept: 'jpeg|jpg'
				}
			},
			invalidHandler: function(form, validator) {
				var errors = validator.numberOfInvalids();
				if (errors) {
					var message = errordata.multiple;
					$("#content .addpoint .error_box").html(message);
					$("#content .addpoint .error_box").show();
				} else {
					$("#content .addpoint .error_box").hide();
				}
		    },
			errorPlacement: function(error, element) {
				/* */
			},
			highlight: function(element, errorClass, validClass) {
				$(element).addClass(errorClass).removeClass(validClass);
				$(element.form).find("label[for=" + element.id + "]").addClass(errorClass);
			},
			unhighlight: function(element, errorClass, validClass) {
				$(element).removeClass(errorClass).addClass(validClass);
				$(element.form).find("label[for=" + element.id + "]").removeClass(errorClass);
			}
		});
	}
}


submitPointSuccess = function(){

	/* REMOVE CONTENT */
	$('.addpoint').empty();
	
	/* SHOW SUCCESS MESSAGE */
	$('.addpoint').html('<span class="right">' + textdata.add_point_succes + '</span>');
}


submitPointFail = function(){

	/* REMOVE CONTENT */
	$('.addpoint').empty();
	
	/* SHOW FAIL MESSAGE */
	$('.addpoint').html('<span class="right">' + textdata.add_point_fail + '</span>');
}

addPoint = function()
{
	/* HIDE ADD BUTTON */
	$(this).hide();
	
	/* SHOW CONTENT */
	$('.addpoint .content').show();
	
	/* CLICK ON CLOSE BUTTON */
	$('.addpoint .closebutton').click(closePoint);
	
	return false;
}

closePoint = function()
{
	/* HIDE CONTACT */
	$('.addpoint .content').hide();
	
	/* SHOW ADD BUTTON */
	$('.addpoint .addbutton').show();
}

initContact = function()
{
	/* VALIDATIONS */
	$("#contactform form").validate({
		focusInvalid: false,
		/* RULES */
		rules: {
			naam: "required",
			email: {
				required: true,
				email:true
			},
			vraag: "required"
		},
		/* MESSAGES */
		messages: {
			naam: errordata.name,
			email: errordata.email,
			vraag: errordata.question
		}
	});
	
	/* SENDFUNCTION CONTACTFORM */
	
	$('#contactform form').submit(function(){
		if($('#contactform form').valid()){
			$('#contactform').load('/'+active_language_code+'/contact/a/submit', $(this).serializeArray());
			
			return false;
		}
	})
}

initMembership = function()
{
	/* VALIDATIONS */
	$(".addmember form").validate({
		focusInvalid: false,
		/* GROUPS */
		groups: {
			adres: "straat nummer",
			plaats: "postcode gemeente"
		},
		/* RULES */
		rules: {
			naam: "required",
			voornaam: "required",			
			email: {
				required: true,
				email:true
			},
			straat: "required",
			nr: "required",
			postcode: "required",
			gemeente: "required"
		},
		/* MESSAGES */
		messages: {
			naam: errordata.name,
			voornaam: errordata.firstname,
			email: errordata.email,
			straat: errordata.address,
			nr: errordata.address,
			postcode: errordata.city,
			gemeente: errordata.city
		},
		/* ERROR PLACEMENT */
		errorPlacement: function(error, element) {
			if (element.attr("name") == "straat" || element.attr("name") == "nummer" )
				error.insertAfter("#nummer");
			else if (element.attr("name") == "postcode" || element.attr("name") == "gemeente" )
				error.insertAfter("#gemeente");
			else
				error.insertAfter(element);
		},
   		debug:true
	});
	
	/* SENDFUNCTION CONTACTFORM */
	
	$('.addmember form').submit(function(){
		if($('.addmember form').valid()){
			$('.addmember').load('/'+active_language_code+'/users/membership/a/addmember', $(this).serializeArray());
			
			return false;
		}
	})
}

loadMap = function()
{
	/* SET VARIABLES */
	if (is_search){
		var start = new google.maps.LatLng(car_location.lat,car_location.lng);
	} else {
		var start = new google.maps.LatLng(50.8503396,4.3517103);
	}
	
	if (is_search){
    	var zoomLevel = 10;
    }else{
    	var zoomLevel = 8;
    }
    
    /* SET MAP OPTIONS */
    var options = {
	    zoom: zoomLevel,
	    center: start,
	    mapTypeId: google.maps.MapTypeId.ROADMAP,
	    navigationControlOptions: {
      		style: google.maps.NavigationControlStyle.SMALL
    	}
	}
	
	/* MAKE NEW MAP */
	map = new google.maps.Map($('#map')[0], options);
	
	/* MAP BOUNDS */
	bounds = new google.maps.LatLngBounds();
		
	/* LOAD SIDEBAR */
	if(pagedata.name=='locations')
		loadLocations();
	else if(pagedata.name=='evs')
		loadEvs();
	
	/* POSITION ICON SETTINGS */
	var iconSize = new google.maps.Size(27, 27);
	var iconPosition = new google.maps.Point(0, 0);
	var iconHotSpotOffset = new google.maps.Point(13, 13);
	var infoWindowAnchor = new google.maps.Size(23, 17);
	
	var iconImageUrl = "/images/location_marker_current.png";
	
	var markerImage = new google.maps.MarkerImage(iconImageUrl, iconSize, iconPosition, iconHotSpotOffset);
	
	/* ADD POSITION */
	if (is_search){
	  	var point = new google.maps.LatLng(car_location.lat,car_location.lng);
	  		
		var positionOptions = {
			title: "",
			icon: markerImage,
			position: point,
			map: map
		}
		
		var position = new google.maps.Marker(positionOptions);
		position.setZIndex(9999);
		
		mapMarkers.push(position);
		bounds.extend(point);
	}
	
	// SET MAP BOUNDS
	if (is_search){
		map.fitBounds(bounds);
	}
}

loadLocations = function()
{
	for(var i = 0; i < locations.length; i++){
		
		/* GET DATA FOR MARKER */
	    var point = new google.maps.LatLng(locations[i].lat,locations[i].lng);
	    var label = locations[i].name;
	    var address = locations[i].address;
	    var description = locations[i].description;
	    var icon = locations[i].icon;
	    
	    /* INSERT COUNT */
	    var count = i;
		
		/* ADD MARKER */
		var marker = createMarker(map,point,label,address,description,icon,count);
		
		mapMarkers.push(marker);
		
		/* CONSTRUCT HTML */
		var htmls = '<table class="content">';
			
			htmls += '<tr>';
				htmls += '<td class="title"><h4>' + label + '</h4></td>';
			htmls += '</tr>';
			
			htmls += '<tr>';
				htmls += '<td class="address">' + address + '</td>';
			htmls += '</tr>';
			
			/*if(description)
			{
				htmls += '<tr>';
					htmls += '<td class="spacer"></td>';
				htmls += '</tr>';
				
				htmls += '<tr>';
					htmls += '<td class="description">' + description + '</td>';
				htmls += '</tr>';
			}*/
			
		htmls += '</table>';
		
      	mapHTMLS.push(htmls);
      	
      	if (is_search)
      	{
      		if(i < 2)
	      	{
	      		bounds.extend(point);
	      	}
      	}else{
      		/* bounds.extend(point); */
      	}
      	
	}
}

createMarker = function(map, latlng, title, address, description, icon, count)
{
	/* ICON SETTINGS */	
	var iconSize = new google.maps.Size(28, 38);
	var iconShadowSize = new google.maps.Size(44, 38);
	var iconHotSpotOffset = new google.maps.Point(28, 38);
	var iconPosition = new google.maps.Point(0, 0);
	var infoWindowAnchor = new google.maps.Size(23, 17);
	
	if (icon!=''){
		var iconImageUrl = "/images/location_marker_" + icon + ".png";
	} else {
		var iconImageUrl = "/images/location_marker_default.png";
	}
	
	var iconShadowUrl = "/images/location_marker_shadow.png";
	
	var markerImage = new google.maps.MarkerImage(iconImageUrl, iconSize, iconPosition, iconHotSpotOffset);
	var markerShadow = new google.maps.MarkerImage(iconShadowUrl, iconShadowSize, iconPosition, iconHotSpotOffset);
	
	
	/* SET MARKER OPTIONS */
	var markerOptions = {
		title: title,
		icon: markerImage,
		shadow: markerShadow,
		position: latlng,
		map: map
	}
	
	/* MAKE MARKER */
	var marker = new google.maps.Marker(markerOptions);
	
	/* MARKER CLICK EVENT */
	google.maps.event.addListener(marker, 'click', function() {
		/* CONSTRUCT HTML */
		var content = '<table class="content">';
			
			content += '<tr>';
				content += '<td class="title"><h4>' + title + '</h4></td>';
			content += '</tr>';
			
			content += '<tr>';
				content += '<td class="address">' + address + '</td>';
			content += '</tr>';
			
			/*if(description)
			{
				content += '<tr>';
					content += '<td class="spacer"></td>';
				content += '</tr>';
				
				content += '<tr>';
					content += '<td class="description">' + description + '</td>';
				content += '</tr>';
			}*/
			
		content += '</table>';
		
		/* SET WINDOW OPTIONS */
		var infowindowOptions = {
			content: content,
			pixelOffset: infoWindowAnchor
		}
		
		/* MAKE WINDOW */
		var infowindow = new google.maps.InfoWindow(infowindowOptions);
		
		/* CHECK OPENED WINDOW */
		setInfowindow(infowindow);
		
		if (is_search){
			/* GET MORE CONTAINER */
			moreContainer = $('#location_' + count).children('.extra').children('.more');
			moreToggle = $('#location_' + count).children('.extra').children('.toggle');
			
			/* CHECK IF CURRENT INFO IS VISIBLE */
			if (!moreContainer.is(':visible')){
			
				/* CHECK FOR OPENED MORE CONTAINERS */
				if ($('.location .more:visible').length!=0){
				
					/* SLIDE UP VISIBLE CONTAINER */
					$('.location .more:visible').slideUp();
					
					/* TOGGLE ARROW */
					$('.location .toggle.open').removeClass('open');
				}
			
				/* CHECK IF MORE CONTAINER EXISTS */
				if (moreContainer.length!=0)
				{
					/* SLIDE DOWN CURRENT CONTAINER */
					moreContainer.slideDown();
					
					/* TOGGLE ARROW */
					moreToggle.addClass('open');
				}
			}
			
			/* WINDOW CLOSE EVENT */
			google.maps.event.addListener(infowindow,'closeclick', function() { 
			
	        	/* CHECK IF MORE CONTAINER EXISTS */
				if (moreContainer.length!=0)
				{
					/* SLIDE UP CURRENT CONTAINER */
					moreContainer.slideUp();
					
					/* TOGGLE ARROW */
					moreToggle.removeClass('open');
				}
	        });
	        
	        /* SHOW WINDOW */
			infowindow.open(map, marker);
        } else {
        
        	/* EMPTY HTML */
        	focusHTML = '';
        	
        	/* CONSTRUCT FOCUS HTML */
        	focusHTML += '<span class="title">' + locations[count].name + '</span>';
        	focusHTML += '<div class="address">' + locations[count].address + '</div>';
        	
        	focusHTML += '<div class="extra">';
        		focusHTML += '<div class="types">';
        		
        			/* GET LABELS */
        			focusLabels = locations[count].label;
        		
        			/* LOOP THROUGH LABELS */
        			$.each(focusLabels, function(index, value){
        				focusHTML += '<img src="/images/location_icon_' + focusLabels[index].icon + '.gif" alt="' + focusLabels[index].title + '" title="' + focusLabels[index].title + '" />';
        			});
        			
        		focusHTML += '</div>';
        		
        		/* GET SPECS */
        		focusSpecs = locations[count].specs;
        		
        		/* CHECK SPECS LENGTH */
        		if(focusSpecs.length!=0){
        			focusHTML += '<span class="subtitle">' + textdata.specs + '</span>';
        		
	        		focusHTML += '<ul class="specs">';
	
	        			/* LOOP THROUGH SPECS */
	        			$.each(focusSpecs, function(index, value){
	        				focusHTML += '<li>' + focusSpecs[index] + '</li>';
	        			});
	        		
	        		focusHTML += '</ul>';
        		}
        		
        		/* CHECK IF DESCRIPTION IS NOT EMPTY */
        		if(locations[count].description!=''){
        			focusHTML += '<span class="subtitle">' + textdata.details + '</span>';
        		
        			focusHTML += locations[count].description;
        		}
        		
        		/* CHECK IF VISUAL IS NOT EMPTY */
        		if(locations[count].visual!=''){
        			focusHTML += '<img src="/skylimit/uploads/normal_' + locations[count].visual + '" alt="' + locations[count].name + '" class="visual"/>';
        		}
        	
        	focusHTML += '</div>';
        	
        	/* ADD TO FOCUS BAR */
        	$('#focus .content').html(focusHTML);
        
        	/* CHECK IF MAP IS NOT ALLREADY RESIZED */
        	if($('#map').width()!=480){
        	
	        	/* RESIZE MAP */
	        	$('#maparea').animate({
					width: 480
				},{
					duration: 300,
					/* NO QUEUE FOR ME! */
					queue: false
				});
					
				$('#map').animate({
					width: 480
				},{
					duration: 300,
					/* NO QUEUE FOR ME! */
					queue: false,
					complete: function() {
					
						/* SHOW FOCUS BAR */
						$('#focus .content').show();
						
						/* CENTER MARKER */
						google.maps.event.trigger(map, 'resize');
						
						/* SHOW WINDOW (DELAYED TO END OF ANIMATION) */
						infowindow.open(map, marker);
					}
				});
			} else {
				/* SHOW WINDOW */
				infowindow.open(map, marker);
			}
			
			/* WINDOW CLOSE EVENT */
			google.maps.event.addListener(infowindow,'closeclick', function() { 
			
				/* EMPTY FOCUS BAR */
				$('#focus .content').empty();
			
	        	/* HIDE FOCUS BAR */
				$('#focus .content').hide();
				
				/* RESIZE MAP */
	        	$('#maparea').animate({
					width: 710
				},{
					duration: 300,
					queue: false
				});
					
				$('#map').animate({
					width: 710
				},{
					duration: 300,
					queue: false
				});
	        });
        }
	});
	
	/* RETURN MARKER */
	return marker;
}



function markerClicked(markerNum) {
	var infowindowOptions = {
		content: mapHTMLS[markerNum],
		pixelOffset: new google.maps.Size(23, 17)
	}
	
	var infowindow = new google.maps.InfoWindow(infowindowOptions);
	infowindow.open(map, mapMarkers[markerNum]);
	setInfowindow(infowindow);
}

function setInfowindow(newInfowindow) {
	if (openInfowindow != undefined) {
		openInfowindow.close();
	}
	
	openInfowindow = newInfowindow;
}


function loadEvs()
{
	for(var i = 0; i < locations.length; i++){
		
		/* GET DATA FOR MARKER */
	    var point = new google.maps.LatLng(locations[i].lat,locations[i].lng);
	    
	    /* INSERT COUNT */
	    var count = i;
		
		/* ADD MARKER */
		var marker = createMarkerEV(map,point,locations[i]);
		
		mapMarkers.push(marker);
		
		/* CONSTRUCT HTML */
		var htmls = '<table class="content">';
			
			htmls += '<tr>';
				htmls += '<td class="title"><h4>' + locations[i].name + '</h4></td>';
			htmls += '</tr>';
			
			htmls += '<tr>';
				htmls += '<td class="address">' + locations[i].address + '</td>';
			htmls += '</tr>';
			
		htmls += '</table>';
		
      	mapHTMLS.push(htmls);

	}

}

createMarkerEV = function(map, latlng, location)
{
	/* ICON SETTINGS */	
	var iconSize = new google.maps.Size(28, 38);
	var iconShadowSize = new google.maps.Size(44, 38);
	var iconHotSpotOffset = new google.maps.Point(28, 38);
	var iconPosition = new google.maps.Point(0, 0);
	var infoWindowAnchor = new google.maps.Size(23, 17);
	
	if (location.icon!=''){
		var iconImageUrl = "/images/location_marker_" + location.icon + ".png";
	} else {
		var iconImageUrl = "/images/location_marker_default.png";
	}
	
	var iconShadowUrl = "/images/location_marker_shadow.png";
	
	var markerImage = new google.maps.MarkerImage(iconImageUrl, iconSize, iconPosition, iconHotSpotOffset);
	var markerShadow = new google.maps.MarkerImage(iconShadowUrl, iconShadowSize, iconPosition, iconHotSpotOffset);
	
	
	/* SET MARKER OPTIONS */
	var markerOptions = {
		title: location.name,
		icon: markerImage,
		shadow: markerShadow,
		position: latlng,
		map: map
	}
	
	/* MAKE MARKER */
	var marker = new google.maps.Marker(markerOptions);
	
	/* MARKER CLICK EVENT */
	google.maps.event.addListener(marker, 'click', function() {
		/* CONSTRUCT HTML */
		
		var content = '<table class="content">';
			
			content += '<tr>';
				content += '<td class="title"><h4>' + location.name + '</h4></td>';
			content += '</tr>';
			
			content += '<tr>';
				content += '<td class="address">' + location.address + '</td>';
			content += '</tr>';
			
			/*if(description)
			{
				content += '<tr>';
					content += '<td class="spacer"></td>';
				content += '</tr>';
				
				content += '<tr>';
					content += '<td class="description">' + description + '</td>';
				content += '</tr>';
			}*/
			
		content += '</table>';
		
		/* SET WINDOW OPTIONS */
		var infowindowOptions = {
			content: content,
			pixelOffset: infoWindowAnchor
		}
		
		/* MAKE WINDOW */
		var infowindow = new google.maps.InfoWindow(infowindowOptions);
		
		/* CHECK OPENED WINDOW */
		setInfowindow(infowindow);
		
       
    	/* EMPTY HTML */
    	focusHTML = '';
    	
    	/* CONSTRUCT FOCUS HTML */
    	focusHTML += '<span class="title">' + location.name + '</span>';
    	focusHTML += '<div class="address">' + location.address + '</div>';
    	
    	focusHTML += '<div class="extra">';
			focusHTML += '<div class="types">';
		
				focusHTML += '<img src="/images/location_icon_' + location.icon + '.gif" alt="' + location.category + '" title="' + location.category + '" style="float: left;"/> <strong>' + location.category+'</strong>';
		
			focusHTML += '</div>';
		
			focusHTML += '<div><strong>'+fieldnames.purchasedate+':</strong><br/> '+ location.purchasedate +'</div>';
			focusHTML += '<div><strong>'+fieldnames.brand_type+':</strong><br/> '+ location.brand_type +'</div>';
			focusHTML += '<div><strong>'+fieldnames.technology+':</strong><br/> '+ location.technology +'</div>';
			focusHTML += '<div><strong>'+fieldnames.performance+':</strong><br/> '+ location.performance +'</div>';
			focusHTML += '<div><strong>'+fieldnames.amount+':</strong> '+ location.amount +'</div>';
		
		
		if(location.visual!=''){
			focusHTML += '<img src="/skylimit/uploads/normal_' + location.visual + '" alt="' + location.name + '" class="visual"/>';
		}
    	
    	focusHTML += '</div>';
    	
    	/* ADD TO FOCUS BAR */
    	$('#focus .content').html(focusHTML);
    
    	/* CHECK IF MAP IS NOT ALLREADY RESIZED */
    	if($('#map').width()!=480){
    	
        	/* RESIZE MAP */
        	$('#maparea').animate({
				width: 480
			},{
				duration: 300,
				queue: false
			});
				
			$('#map').animate({
				width: 480
			},{
				duration: 300,
				queue: false,
				complete: function() {
				
					/* SHOW FOCUS BAR */
					$('#focus .content').show();
					
					/* CENTER MARKER */
					google.maps.event.trigger(map, 'resize');
					
					/* SHOW WINDOW (DELAYED TO END OF ANIMATION) */
					infowindow.open(map, marker);
				}
			});
		} else {
			/* SHOW WINDOW */
			infowindow.open(map, marker);
		}
		
		/* WINDOW CLOSE EVENT */
		google.maps.event.addListener(infowindow,'closeclick', function() { 
		
			/* EMPTY FOCUS BAR */
			$('#focus .content').empty();
		
        	/* HIDE FOCUS BAR */
			$('#focus .content').hide();
			
			/* RESIZE MAP */
        	$('#maparea').animate({
				width: 710
			},{
				duration: 300,
				queue: false
			});
				
			$('#map').animate({
				width: 710
			},{
				duration: 300,
				queue: false
			});
        });
	});
	
	/* RETURN MARKER */
	return marker;
}







toggleMenu = function()
{	
	/* TOGGLE MENU */
	$childlist = $(this).next();
	
	if($childlist.length)
	{
		if(!$childlist.is(":visible"))
		{
			$childlist.slideDown(350);
			$(this).parent().addClass('open');
		}else{
			$childlist.slideUp(350, function() {
    			$(this).parent().removeClass('open');
 			 });
		}
		
		return false;
	} else {
		return true;
	}
}

theRotator = function() {
	/* SET STYLES */
	$('div#rotator ul li').css({opacity: 0.0});
	$('div#rotator ul li:first').css({opacity: 1.0});
	$('div#rotator ul li:first').addClass('show');
	
	/* SET INTERVAL */
	setInterval('rotateVisual()',3000);
}

rotateVisual = function() {	
	/* ROTATE! */
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	
	
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
};




function initEvs()
{
	console.log($(".addform form").length);
	
	$(".addform form").validate({
		focusInvalid: false,
		/* RULES */
		rules: {
			name: "required",
			email: {
				required: true,
				email:true
			},
			address: "required",
			zip: "required",
			city: "required",
			photo: {
				accept: 'jpeg|jpg'
			}
		},
		invalidHandler: function(form, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errordata.multiple;
				$("#content .addform .error_box").html(message);
				$("#content .addform .error_box").show();
			} else {
				$("#content .addform .error_box").hide();
			}
	    },
		errorPlacement: function(error, element) {
			/* */
		},
		highlight: function(element, errorClass, validClass) {
			$(element).addClass(errorClass).removeClass(validClass);
			$(element.form).find("label[for=" + element.id + "]").addClass(errorClass);
		},
		unhighlight: function(element, errorClass, validClass) {
			$(element).removeClass(errorClass).addClass(validClass);
			$(element.form).find("label[for=" + element.id + "]").removeClass(errorClass);
		}
	});

		
/*
	$('.addpoint form').submit(function(){
		if($(this).valid())
			return true;
		else
			return false;
	})
*/
}
