
// contains js for use sitewide

window.addEvent('domready',function() {

	if($('container')) { $('container').setStyle('display','block'); }

	// initiates slideshows
	var myShow = new Slideshow("leftshow", null, { delay: 4000, duration: 2000, captions: false, controller: false, loader:true });
	//var myShow = new Slideshow("rightshow", null, { delay: 4000, duration: 2000, captions: false, controller: false, loader:true });

	// attempts to equalize column heights
	var columns = $$('.equalize');
	var max_height = 0;
	
	columns.each(function(item) 
	{ max_height = Math.max(max_height, item.getSize().y); });
	
	columns.setStyle('height', max_height);

	// makes whole submit button a link
	$$('p.submit').addEvent("click",function(b) {
		this.getParent('form').submit();
	}).addEvent('mouseenter',function(ev){
		this.setStyle('cursor','pointer');
	});
	
	// make the whole of the li in the top nav a link
	$$('#nav ul li').addEvent("click",function(c) {
		location.href = '/'+this.getElement('a').getProperty('href');
	});

	// automatically submits development chosen from drop down menu on LH Col
	$("choosedevelopment").addEvent("click",function(ev){
		if (ev) ev.stop();
		if(this.get('value') == '') return;
		location.href = 'http://www.themcginnisgroup.com/developments/' + this.get('value');
	});
	
	/*
	// on click goes to the development page
	// this was whenever we had a click button for the development drop down
	$("gotodev").addEvents({
		'click' : function(ev){
			ev.stop();
			location.href = 'http://www.themcginnisgroup.com/developments/' + $('choosedevelopment').getProperty('value');
		},
		'mouseenter' : function() {
			this.setStyle('cursor','pointer');		
		}
	});
	*/
	
	// map roll over
	if($("ukmap")) {
		$$('map area').addEvents({
			'mouseenter' : function() { 
				this.setStyle('cursor','pointer');
				$("ukmap").setProperty('src','images/map-' + this.getProperty('id') + '.png'); 
			},
			'mouseleave' : function() {
				$("ukmap").setProperty('src','images/map-base.png');
			}
		});
	}
/*									
	$$('.multiple_select').each(function(el){
		new MultipleSelect(el);
	});

	$("development").getElement('div.arrowup').addEvent("click",function(b) {
	
		var start = 0;
		var display = 1;
		var cont = true;
		var counter = 0;
		var prev = false;
		
		if($$('ul.developments li.active').length > 0){

			$$('ul.developments li').each(function(c) {
				if(cont){
					if(c.hasClass('active')){
						cont = false;
						start--;
					}
					else start++;
				}
			});
									
			if(start < 0){
				start = 0;
			}
		
		} else {
			start = 0;
		}
					
		$$('ul.developments li').removeClass('active').setStyle('display','none');
											
		$$('ul.developments li').each(function(c){
			if(counter >= start){
				c.addClass('active');
				c.setStyle('display','block');
				if(c.getNext('li')){
					c.getNext('li').setStyle('display','block');
				}
			}
			counter++;
		});
		
		}).addEvent('mouseenter',function(ev){
			$$("div.arrowup").setStyle('cursor','pointer');
		});
		
*/

/*
	$("development").getElement('div.arrowdown').addEvent("click",function(v) {
	
		var start = 0;
		var display = 1;
		var cont = true;
		var counter = 0;
		var prev = false;
					
		if($$('ul.developments li.active').length > 0){

			$$('ul.developments li').each(function(c) {
				if(cont){
					if(c.hasClass('active')){
						cont = false;
						start++;
					}
					else start++;
				}
			});
									
			if(start > ($$('ul.developments li').length - display)){
				start = $$('ul.developments li').length - display;
			}
		
		} else {
			start = 1;
		}
		
		$$('ul.developments li').removeClass('active').setStyle('display','none');
											
		$$('ul.developments li').each(function(c){
			if(counter >= start){
				c.addClass('active');
				c.setStyle('display','block');
				if(c.getNext('li')){
					c.getNext('li').setStyle('display','block');
				}
			}
			counter++;
		});
		
		}).addEvent('mouseenter',function(ev){
			$$("div.arrowdown").setStyle('cursor','pointer');
		});
		
*/		
	// development tabs
	$$('ul.sublinks li').addEvent('click',function(ev){
		if (ev) ev.stop();
		if(!this.hasClass('selected')){
			var changeMe = 't-'+this.getProperty('id');
			$$('ul.sublinks li').removeClass('selected');
			this.addClass('selected');
			$$('table.tab td div.showtab').removeClass('showtab');
			$$('#'+changeMe).addClass('showtab');
		}
	}).addEvent('mouseenter',function(ev){
		$$("ul.sublinks li").setStyle('cursor','pointer');
	});
		
	var pg_page = 0;
	var pg_count = $$('div.page').length;
	
	$$('div.page').setStyle('display','none');
	if ($('pg_page'+pg_page)) $('pg_page'+pg_page).setStyle('display','block');
	if ($('pglink_prev')) $('pglink_prev').setStyle('display','none');
	
	changePage = function (p) {
		
		pg_page += p;
		if (pg_page < 0) pg_page = 0;
		if (pg_page >= pg_count) pg_page = pg_count - 1;
		
		if (pg_page == 0){
			$('pglink_prev').setStyle('display','none');		
		} else {
			$('pglink_prev').setStyle('display','inline');
		}
		
		if (pg_page >= pg_count - 1){
			$('pglink_next').setStyle('display','none');		
		} else {
			$('pglink_next').setStyle('display','inline');
		}
	
		$$('div.page').setStyle('display','none');
		if ($('pg_page'+pg_page)) $('pg_page'+pg_page).setStyle('display','block');
		
	}
		
		
});	

	
