function openFormDialog(f) 
{	
	var divwidth = 850;
	var divheight =600;

	var window_width = get_document_window_width();
   	var width = convert_width(divwidth,window_width);
   	var window_height = get_document_window_height();
   	var height = convert_height(divheight,window_height);
   	var left = calculate_left(width,window_width);
   	var top = calculate_top(height,window_height);
	
	//$('formframe').src = '/'+f+'-application.html';
	//$('ajaxforms').style.top = top+'px';
	//$('ajaxforms').style.left = left+'px';
	
	//elementAppear('ajaxforms');
	
	newwindow = window.open ('/'+f+'-application.html', f,"menubar=0,resizable=0,scrollbars=1,screenX="+left+",screenY="+top+",left="+left+",top="+top+",width="+divwidth+",height="+divheight);
	newwindow.focus();
}

function openExternalSite(f) 
{	
	var divwidth = 925;
	var divheight =600;

	var window_width = get_document_window_width();
   	var width = convert_width(divwidth,window_width);
   	var window_height = get_document_window_height();
   	var height = convert_height(divheight,window_height);
   	var left = calculate_left(width,window_width);
   	var top = calculate_top(height,window_height);
	
	newwindow = window.open (f, "externalsite","menubar=0,resizable=0,scrollbars=1,screenX="+left+",screenY="+top+",left="+left+",top="+top+",width="+divwidth+",height="+divheight);
	newwindow.focus();
}


function swapDiv(newcont)
{
	
	for(i=1;i<=6;i++)
	{
		if($('active'+i).style.display == '')
			old = 'active'+i;
	}

	if($(newcont).style.display == 'none' && $(old).style.display != 'none')
	{
		elementFade(old);
		$(old+'anchor').className = 'inactive';	
		$(old+'anchor').id = old+'anchor';	
		elementAppear(newcont);
		$(newcont+'anchor').className = 'active';
		$(newcont+'anchor').id = newcont+'anchor';
	}
}

function checkForm(f)
{
	var divwidth  = 300;
	var divheight = 100;

	var window_width = get_document_window_width();
   	var width = convert_width(divwidth,window_width);
   	var window_height = get_document_window_height();
   	var height = convert_height(divheight,window_height);
   	var left = calculate_left(width,window_width);
   	var top = calculate_top(height,window_height);
	
	$('ajaxmessage').style.top = top+'px';
	$('ajaxmessage').style.left = left+'px';
	

	new Ajax.Request('send-email.php', 
					 {
					 	method: 'post',
		 			  	parameters: $(f).serialize(),
						onSuccess: function(transport)
						{
							$('ajaxtext').innerHTML = transport.responseText;
							elementAppear('ajaxmessage');
							$(f).reset();
							reset_captcha();
						},
						onFailure: function(transport)
						{ 
							$('ajaxtext').innerHTML =  transport.responseText;							
							elementAppear('ajaxmessage');
							reset_captcha();
						}
	 				 }
					 );
}

function reset_captcha()
{
   var captcha_image = document.getElementById('join_captcha_image');
   var date_value = new Date();
   captcha_image.src = '/include/CaptchaSecurityImages.php?characters=5&height=18&width=70&bgr=179&bgg=195&bgb=52&CacheTime=' +
                       date_value.getTime();
}

function checkApp(f)
{
	var divwidth  = 300;
	var divheight = 100;

	var window_width = get_document_window_width();
   	var width = convert_width(divwidth,window_width);
   	var window_height = get_document_window_height();
   	var height = convert_height(divheight,window_height);
   	var left = calculate_left(width,window_width);
   	var top = calculate_top(height,window_height);
	
	$('ajaxmessage').style.top  = top+'px';
	$('ajaxmessage').style.left = left+'px';
	

	new Ajax.Request('/admin/formmailer.php', 
					 {
					 	method: 'post',
		 			  	parameters: $(f).serialize(),
						onSuccess: function(transport)
						{
							alert( transport.responseText);
							//elementAppear('ajaxmessage');
							self.close();
						},
						onFailure: function(transport)
						{ 
							alert( transport.responseText);							
							//elementAppear('ajaxmessage');
							//Recaptcha.reload();
						}
	 				 }
					 );
}

function get_document_window_height()
{
   if (document.body && document.body.clientHeight &&
       (document.body.clientHeight > 1)) return document.body.clientHeight;
   else if (window && window.innerHeight) return window.innerHeight;
   else if (document.documentElement && document.documentElement.offsetHeight)
      return document.documentElement.offsetHeight;
   else if (document.body && document.body.offsetHeight)
      return document.body.offsetHeight;
   return 0;
}

function get_document_window_width()
{
   if (document.body && document.body.clientWidth)
      return document.body.clientWidth;
   else if (window && window.innerWidth) return window.innerWidth;
   else if (document.documentElement && document.documentElement.offsetWidth)
      return document.documentElement.offsetWidth;
   else if (document.body && document.body.offsetWidth)
      return document.body.offsetWidth;
   return 0;
}

function convert_width(width,window_width)
{
   if (width == null) width = page_width + 52;
   else if (typeof(width) == 'string') {
      var percent_pos = width.indexOf('%');
      if (percent_pos != -1)
         width = window_width * (width.substr(0,percent_pos) / 100);
   }
   if (! document.all) {
      if (width > (window_width - 25)) width = window_width - 25;
   }
   else if (width > (window_width - 10)) width = window_width - 10;
   return width;
}

function convert_height(height,window_height)
{
   if (height == null) height = window_height;
   else if (typeof(height) == 'string') {
      var percent_pos = height.indexOf('%');
      if (percent_pos != -1)
         height = window_height * (height.substr(0,percent_pos) / 100);
   }
//   else height += header_offset;
   if (height > (window_height - 40)) height = window_height - 40;
   return height;
}

function calculate_left(width,window_width)
{
   var left = (window_width - width) / 2;
   if (! document.all) left += 10;
   if (left < 0) left = 0;
   return left;
}

function calculate_top(height,window_height)
{
   var top = ((window_height - height) / 2) - 3;
   if (top < 0) top = 0;
   return top;
}

function loadFlash(f) 
{	
	$('commercials').innerHTML = AC_FL_PreloadContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','760','height','300','movie','portfolio/portfolio?page='+f,'quality','high','allowfullscreen','false','wmode','transparent' );
}

function showVideo(f,fi,vw,vh) 
{	
	var divwidth  = vw;
	var divheight = vh;

	var window_width = get_document_window_width();
   	var width = convert_width(divwidth,window_width);
   	var window_height = get_document_window_height();
   	var height = convert_height(divheight,window_height);
   	var left = calculate_left(width,window_width);
   	var top = calculate_top(height,window_height);
	
	//$('commercialstext').style.paddingTop = '10px';
	
	//$('commercialbox').style.display = '';
	//elementAppear('commercialdiv');
	$('commercials').className = ''; 
	$('commercials').innerHTML = AC_FL_PreloadContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width',vw,'height',vh,'movie','portfolio/flvplayer?autoStart=false&videoPath='+f+'&imagePath=portfolio/'+fi,'quality','high','allowfullscreen','false','wmode','transparent' );
}

function showExternalVideo(p,f,fi,vw,vh,autostart) 
{	
	var divwidth  = vw;
	var divheight = vh;

	var window_width = get_document_window_width();
   	var width = convert_width(divwidth,window_width);
   	var window_height = get_document_window_height();
   	var height = convert_height(divheight,window_height);
   	var left = calculate_left(width,window_width);
   	var top = calculate_top(height,window_height);
	
	//$('commercialstext').style.paddingTop = '10px';
	
	//$('commercialbox').style.display = '';
	//elementAppear('commercialdiv');
	$('commercials').className = ''; 
	$('commercials').innerHTML = AC_FL_PreloadContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width',vw,'height',vh,'movie',p+'flvplayer?autoStart='+autostart+'&videoPath='+f+'&imagePath=portfolio/'+fi,'quality','high','allowfullscreen','false','wmode','transparent' );
}

function hideVideo() 
{	
	
	elementFade('commercialdiv');
	$('commercials').innerHTML = '';
	$('commercialbox').style.display = 'none';
}

function AC_FL_PreloadContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  return AC_GenerateText(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GenerateText(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  return str;
}	

 function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}
//add_onload_function(function(){add_video_full('irish_video',640,429,'swf/irish');});
function openIrishVideo(){
	var opts = {
			draggable:false,
			id:'irishvid',
			static_top:133,
			add_overlay:true,
			overlay:null,
			hide_only:false,
			anchored:false,
			corners:{
				top_left:false,
				bottom_left:false,
				top_right:false,
				bottom_right:false
			},
			padding:false,
			element:{
				obj:null,
				handle:null,
				data:null
			},
			center_view:true
	}
	msgtxt='<div style="position:relative;"><iframe title="YouTube video player" width="640" height="390" src="http://www.youtube.com/embed/bDkmn5ipswY?rel=0" frameborder="0" allowfullscreen></iframe>';
	msgtxt+='<div style="position:absolute; top:345px; left:0px; width:640px;height:45px;background-color:#ffffff;"></div></div>';
	create_show_div_dialogs(opts,"Don't Play SHENANIGANS! This offer expires 03.31.11.",{width:640,height:""},msgtxt,false,false)
}
function refresh(){
  window.location.reload();
}
add_onload_function(function(){
  if($('map')) {  
    var dpanel;
    gmap = new gmLocator('map');
    if ($('directions')) {
	  //log('directions');
      gmap.options.marker_clickable = false;
      gmap.options.marker_draggable = false;
      gmap.options.largemapcontrol3d = true;
      gmap.options.map_draggable = true;
      gmap.options.maptypecontrol = true;
      gmap.map_options.scaleControl = true;
      gmap.map_options.streetViewControl = true;
      gmap.map_options.zoom = 15;
    }
    else {
	  //log('not direcitons');
      gmap.options.marker_clickable = true;
      gmap.options.marker_draggable = false;
      gmap.options.smallzoomcontrol3d = true;
      gmap.options.maptypecontrol = true;
      gmap.options.map_draggable = false;
      gmap.map_options.zoom = 14;
      gmap.map_options.scrollwheel = false;
    }
    //log('loading markers');
    gmap.Markers = new Markers();
    gmap.get_address();
    //log('directions block?');
    gmap.Directions = new Directions(gmap.map,gmap.options);
    gmap.Directions.Markers = new Markers();
  }
});
