/* javascript functionality for discoverdartmouth.com by stuart sillitoe for pulse8.co.uk 2006 */

function addLoadEvent(func) 
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function') 
	{
		window.onload = func;
	} 
	else 
	{
		window.onload = function() 
		{
			if (oldonload) 
			{
				oldonload();
			}
			func();
		}
	}
}


addLoadEvent(prepareVerifyCode);



d = document;

// regexp for email addresses
var pattern = /^[a-zA-Z0-9\-\._]+@[a-zA-Z0-9\-_]+(\.?[a-zA-Z0-9\-_]*)\.[a-zA-Z]{2,8}$/;


function antispam(email)
{
	// get string (convert to lowercase)
	s = email.toLowerCase();
	
	// find length of string
	strLen = s.length;
	
	// clear value of new string
	newStr = "";
	
	// loop through characters from last to first
	for (i=strLen-1;i>-1;i--)
	{
		// build new string
		newStr = "&#" + s.charCodeAt(i) + ";" + newStr;
	}
	
	return newStr;

}




function prepareVerifyCode()
{
	if ( d.getElementById('verifyLink') )
	{
		var verifyLink = d.getElementById('verifyLink');
		verifyLink.onmouseover = showVerifyCodeHelp;
		verifyLink.onmouseout = hideVerifyCodeHelp;
		verifyLink.onclick = returnFalse;
	}
}


function showVerifyCodeHelp()
{
	document.getElementById('verifyHelp').style.display = 'block';
}


function hideVerifyCodeHelp()
{
	document.getElementById('verifyHelp').style.display = 'none';
}

function returnFalse()
{
	return false;
}





function showSymbolsTable()
{
	var div = d.getElementById('symbolsTable');
	var divS = d.getElementById('symbolsTableShadow');
	//var link = d.getElementById('symbolsLinkImg');
	
	//link.setAttribute('src', 'images/arrow-up.gif');	
	div.style.display = '';
	divS.style.display = '';
}

function hideSymbolsTable()
{
	var div = d.getElementById('symbolsTable');
	var divS = d.getElementById('symbolsTableShadow');
	//var link = d.getElementById('symbolsLinkImg');

	//link.setAttribute('src', 'images/arrow-down.gif');
	div.style.display = 'none';
	divS.style.display = 'none';
}



// on dom load...
$(function()
{
	// get only links that start with https cos we were getting the email links too sir :)
	//$('.eventBox a[@href^=http]').click(function()
	$('a.place_link').click(function()
	{
		var theId 	= $(this).attr('id').replace('place_link','');
		var theHref = $(this).attr('href');
		// use the callback to send them to the links href...
		$.get('../stat.php', {id: theId}, function()
		{ 
			window.location = theHref;
		});
		return false;
	});
	
	
	$('*').each(function(){
		
		//alert($(this).css('background-color'));
		
		if($(this).css('background-color')=='#0074B1' ){
			$(this).css({
				'background-color':'red'
			});
		}
		
	});
	
	$('#theme_mainimage').cycle();
	
	if($('#theme_acc_search').height() < $('#theme_detail').height()){
		$('#theme_acc_search').height($('#theme_detail').height())
	}
	
	//if($.browser.msie){
		$('input').each(function(){
			if($(this).attr('type')=='checkbox'){
				$(this).css('border','0');
			}
		});
	//}
	
	$('div.theme_detail_container').css('zoom','1');
	
	$('#place_images span:eq(0)').css('border-right','1px solid #fff');
	$('#place_images span:eq(2)').css('border-right','1px solid #fff');
	
	$('#place_images span').each(function(){
		
		var spanHeight = 186;
		var imgHeight = 0;
		$('img',this).each(function(){
			imgHeight = $(this).height();
		});
		
		$(this).css('padding-top', ((spanHeight-imgHeight)/2) +'px');
		$(this).css('padding-bottom', ((spanHeight-imgHeight)/2) +'px');
	});
	
	if($('#stop_press').html() != '' || $('#stop_press').html() != undefined){
			
		$('#stop_press_cycle').cycle({
			fx:    	'fade', 
			speed: 	1000 ,
	    	timeout:10000
		});
	
		//$('#stop_press_bg').height($('#stop_press').height());
		$('#stop_press_bg').css('opacity','0.8');
		$('#stop_press_bg').height($('#stop_press').height());
		
		$('#stop_press').css('display','block');
		$('#stop_press_bg').css('display','block');
	}
	
	var lHeight = $('#theme_content div.left_panel').height();
	var rHeight = $('#theme_content div.right_panel').height();
	
	if(lHeight < rHeight){
		$('#theme_content div.left_panel').height(rHeight);
	}
	
	if ( $.browser.msie && $.browser.version < 7 )
	{
		$('#theme_detail').css('padding','0px');
		$('.left_panel').css('width','550px');
		$('#theme_detail').css('width','550px');
	}	

	
	
	$('td.date_cell').click(function(){
		
		var strDate = $(this).attr('id').replace('date_cell','');
		
		var objCell = $(this);
		
		$.get('update.availability.php?date='+strDate,function(strHtml){
			objCell.css('background',strHtml);
		});
		
	}).css('cursor','pointer');
	
	$('div.banner_cycle').cycle({
		fx:    	'fade', 
		speed: 	300 ,
    	timeout:10000
	}).css('display','block');
	
});


var min=0;
var max=999;

function increaseFontSize() {
   var p = document.getElementsByTagName('div');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
   
}

function decreaseFontSize() {
   var p = document.getElementsByTagName('div');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }
      
}
