/* @version $Id: default_8-31-2011.js 7803 2011-08-31 17:59:33Z bryan $ */
// JavaScript Document

if((navigator.userAgent.match(/iPad/i))) {
	
// Leave it blank	

}
else
{
document.write("<meta name=\"viewport\" content=\"initial-scale=1.0; maximum-scale=1.0\" \/>");
}

if (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')
document.write('</style>\n')
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v=='hide')?'none':v; }
    obj.display=v; }
}

function idetector() {
	
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/android/i))) {
	MM_showHideLayers('coastwin','','hide');
	MM_showHideLayers('coastwin1','','hide');
	MM_showHideLayers('coastwin2','','hide');
	MM_showHideLayers('coastwin3','','hide');
	MM_showHideLayers('insiderpodcast','','hide');
	MM_showHideLayers('popuptext','','hide');
	MM_showHideLayers('podcasthome1','','hide');
	MM_showHideLayers('podcasthome2','','hide');
		}

if((navigator.userAgent.match(/android/i))) {
	MM_showHideLayers('insideriphone','','hide');
		}
		
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i))) {
	MM_showHideLayers('videotitleblock','','hide');
	MM_showHideLayers('videoexplain','','show');
		}
		
if((navigator.userAgent.match(/iPad/i))) {
	MM_showHideLayers('videoexplain1','','show');
		}
		
	}

function getEmailURL() {
	if (self.emailURL)
		return emailURL;
	else	
		return document.location.href;
}

function getEmailTitle() {
	if (self.emailTitle)
		return emailTitle;
	else	
		return document.title;
}

function getEmailLink() {
	return "/email?mode=email" + "&url=" + escape(getEmailURL()) + "&title=" + escape(getEmailTitle());	
}

function EmailtoFriend() { //v1.0
window.open('http://common.coasttocoastam.com/email/coast/?title='+encodeURIComponent(getClickTitle())+'&url='+encodeURIComponent(getClickURL()),'click',"width=570,height=555,resizable=1,scrollbars=1");
	return false;
}

function getClickURL() {
        if (self.clickURL) {
        	alert(self.clickURL);
        	return clickURL;
        }
        return document.location.href;
}

function PrintThis() { //v1.0
window.open(getClickURL()+'?mode=print','print',"width=630,height=800,scrollbars=1");
	return false;
}

function getClickTitle() {
	if (self.clickTitle) return clickTitle; 
	return clktitle=document.title; 
}

function tweetMe() {
	var msg = getClickTitle();
	var url = getClickURL();
	var textMessage = msg.replace(new RegExp("^(.{0," + 80 + "}\\b).*"), "$1");
	BitlyCB.shortenResponse = function(data) {
		var tweet_url = "http://twitter.com/home?status=" + encodeURIComponent(textMessage+ "... " + data.results[url].shortUrl );
		window.open(tweet_url);
	};
	
	BitlyClient.shorten(url,'BitlyCB.shortenResponse');
}

function MM_showHideLayers1() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers1.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function MM_changeProp(objId,x,theProp,theValue) { //v9.0
  var obj = null; with (document){ if (getElementById)
  obj = getElementById(objId); }
  if (obj){
    if (theValue == true || theValue == false)
      eval("obj.style."+theProp+"="+theValue);
    else eval("obj.style."+theProp+"='"+theValue+"'");
  }
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function amazonPopUp(URL,NAME) {
	amznwin=window.open(URL,NAME,'location=yes,scrollbars=yes,status=yes,toolbar=yes,resizable=yes,width=380,height=450,screenX=10,screenY=10,top=10,left=10');
	amznwin.focus();
}

function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}

function showmenu(elmnt)
{
document.getElementById(elmnt).style.visibility="visible";
}
function hidemenu(elmnt)
{
document.getElementById(elmnt).style.visibility="hidden";
}


// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this notice.

// SETUPS:
// ===============================

// Set the horizontal and vertical position for the popup

PositionX = 100;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
function popImage(imageURL,imageTitle){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE,isChrome;');
writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isChrome=(navigator.appVersion.indexOf("Chrome")!=-1)?1:0;');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');
writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');
writeln('if (isIE){');
writeln('window.resizeTo(300,300);');
writeln('width=300-(document.body.clientWidth-document.images[0].width);');
writeln('height=300-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');
writeln('if (isChrome){');
writeln('width=document.images[0].width;');
writeln('height=document.images[0].height;');
writeln('window.resizeTo(width,height);}');
writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="">');
writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
close();		
}}

function toggle_visibility(id) {
   var e = document.getElementById(id);
   if(e.style.display == 'block')
	  e.style.display = 'none';
   else
	  e.style.display = 'block';
}

var ac3 = String.fromCharCode(0x43,0x54,0x43),ad3 = String.fromCharCode(0x5F),ai3 = [0x1,0x2,0x3],crc = 0,site_visitor = String.fromCharCode(0x67,0x75,0x65,0x73,0x74);
jQuery.each(ai3,function(){var p = $.cookie(ac3+ad3+this);if(p){crc++}});
if(crc==3){site_visitor = String.fromCharCode(0x6D,0x65,0x6D,0x62,0x65,0x72)};

/**
 * used on control bar to form filter requests
 * @param Form f
 * @param String loc 
 * @return mixed
 */
 
function dispatchFilterAction(f,loc){
		if(!f || !loc){
			return false;
		}
		var opt= f.category.options;
		var value = opt[opt.selectedIndex].value;
		if(!value || value.search('#')!=-1){
      return false;
    }
		window.location = loc + '/' + value;
	}


/**
 * processes entered value for gallery pager
 * @param Integer
 * @return boolean 
 */
 
 function pagerSlide(f,url){
  var page = f.page_slide.value;
  var slide_url = url +'/'+page;
  if(page){
    window.location = slide_url;
  }
  return false;
 }

/* COOKIE OBJECT BEGIN */
   
  /**
   * object to handle cookie
   * @param String name
   * @param String path
   */
   
  function PrnCookie(name, path){
	 this.name = name;
	 if(path){
		this.path = path;
	 }
	 else{
		this.path = "/";	
	 }
  }
  
  /**
   * modifier
   * @return void
   */
   
  PrnCookie.prototype.set = function(value,days){
	  var date;
	  var expires = "";
	  if (days) {
		  var date = new Date();
		  date.setTime(date.getTime()+(days*24*60*60*1000));
		  var expires = "; expires="+date.toGMTString();
	  }
	  document.cookie = this.name+"="+value+expires+"; path="+this.path;
  }
  
  /**
   * accessor
   * @return String
   */
  
  PrnCookie.prototype.get = function(){
   var nameEQ = this.name + "=";
	 var ca = document.cookie.split(';');
	 for(var i=0;i < ca.length;i++) {
	 var c = ca[i];
	 while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	 }
	 return '';
  } 
  
  /**
   * erases cookie
   * @return void
   */
   
  PrnCookie.prototype.erase = function(){
  	this.set(this.name,"",-1);
  }
  
  /* COOKIE OBJECT END */
  
var firstCall = true;

function changeFontsize(fSize, increment) {
  if (firstCall) {
    firstCall = false;
    if (increment != "")
      changeFontsize('12', '');
  }
  if (document.getElementsByTagName) {
    tags = new Array ( "p", "li", "h2", "h3", "h4", "h5", "h6", "div" );
    for (j=0; j<tags.length; j++) {
      var getElement = document.getElementsByTagName(tags[j]);
      var eachElement, currentFontSize, fontIncrease, newFontSize;
      for (i=0; i<getElement.length; i++) {
        eachElement = getElement[i];
        if (increment != "") {
          currentFontSize = parseInt(eachElement.style.fontSize);
          fontIncrease = parseInt(increment);
          newFontSize = currentFontSize + fontIncrease;
          }
        else if (fSize != "")
          newFontSize = parseInt(fSize);
        if (tags[j] == "li")
          eachElement.style.lineHeight = Math.round(newFontSize*1.2) + "px";
        else
          eachElement.style.lineHeight = Math.round(newFontSize*1.3) + "px";
        if (fSize != "") {
          switch(tags[j]) {
          case "h2":
            newFontSize += 12;
            var cookie = new PrnCookie('cbfont[h2]');
            cookie.set(newFontSize); 
            break;
          case "h3": 
            newFontSize += 2;
            var cookie = new PrnCookie('cbfont[h3]');
            cookie.set(newFontSize);
            break;
          case "h4": 
            newFontSize += 1;
            var cookie = new PrnCookie('cbfont[h4]');
            cookie.set(newFontSize);
            break;
          case "h5": 
            newFontSize += 1;
            var cookie = new PrnCookie('cbfont[h5]');
            cookie.set(newFontSize);
            break;
          case "h6": 
            var cookie = new PrnCookie('cbfont[h6]');
            cookie.set(newFontSize);
            newFontSize += 1;
          }
        }
        var cookie = new PrnCookie('cbfont[base]');
        cookie.set(newFontSize);
        eachElement.style.fontSize = newFontSize + "px";
      }
    }
  }
}

/**
  * font control class 
  */
  
  function PrnFontControl(){


	    this.containerId = 'internalbody';
	
	this.sizeStepsUp = 1;
    this.sizeStepsDown = -1;
    
	this.base_font = 12;
  }
  
  /**
   * init font tool
   * @return void
   */
  
  PrnFontControl.prototype.init = function(){
	 
		  var cookie = new PrnCookie('cbfont['+this.container+']');
		  if(cookie.get()){
			 this.applyFontSize(this.container,cookie.get());
		  
	      }  
		
  }
  
  /**
   * increases font size
   * @return void
   */
     
  PrnFontControl.prototype.sizeUp = function(){
      this.applyFontIncrement(this.containerId,this.sizeStepsUp);
    
  }
  
 /**
  * decreases font size
  * @return void
  */
     
  PrnFontControl.prototype.sizeDown = function(){
    
      this.applyFontIncrement(this.containerId,this.sizeStepsDown);
    
  }
  
  /**
   * gets current font size of the element
   * @param String tag
   * @param Integer increment   
   * @return void      
   */
     
  PrnFontControl.prototype.applyFontIncrement = function(tag, increment){
    if(!tag || !increment){
      return;
    }
     if(document.getElementById('left_column')){
		tag = 'left_column';
	 }
    var elements = document.getElementById(tag);

	 if(!elements){
		  return;
	  }
	
	  var new_size, current_size;
    var font_increment = parseInt(increment);
	  current_size = parseInt(this.lookupBaseFont(tag));
	  current_size = this.loadFontSize(tag,current_size);
	  new_size = current_size + font_increment;
	

          elements.style.lineHeight = Math.round(new_size*1.3) + 'px';
		   
		   elements.style.fontSize = new_size + 'px';
   
	  this.storeFontSize(tag,new_size);
  }
  
  /**
   * applies font size
   * @param String tag
   * @param Integer size   
   * @return void      
   */
  
  PrnFontControl.prototype.applyFontSize = function(tag, size){
    if(!tag || !size){
      return;
    }
    var elements = document.getElementById(tag);
	  if(!elements){
		  return;
	  }
   
         elements[i].style.lineHeight = Math.round(size*1.3) + 'px';
		 
		 elements[i].style.fontSize = size + 'px';
    
  }
  
  /**
   * looks up base size for the element
   * @param String tag
   * @return Integer      
   */
     
  PrnFontControl.prototype.lookupBaseFont = function(tag){
    return this.base_font;
  }
  
  /**
   * loads font cookie
   * @return Integer
   */
   
  PrnFontControl.prototype.loadFontSize = function(tag,original_fs){
  	if(!tag || !original_fs){
		  return;	
	  }
	  var font = original_fs;
	  var cookie = new PrnCookie('cbfont['+tag+']');
	  var value = cookie.get();
	  if(value){
		  font = parseInt(value);
	  }
	   return font;
  }
   
  /**
   * stores font cookie
   * @return void
   */
   
   PrnFontControl.prototype.storeFontSize = function(tag,font){
  	if(!tag || !font){
		  return;	
	  }
	  var cookie = new PrnCookie('cbfont['+tag+']');
	  cookie.set(parseInt(font));
   }
  
  //init font object
  try{
  	var fontControl = new PrnFontControl();
  }
  catch(e){
    if(window.console){
      window.console.log(e.toString());
    }
  }

function showLink() {
	obj = document.getElementById('permablock');
	obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
	document.getElementById('permafield').value = getClickURL();
	//document.getElementById('permafield').focus();
   document.getElementById('permafield').select();
}

/**
 * banner control
 */
 
 function toggleAds(el_id){
  if(!el_id){
    return;
  }
  try{
    if(site_visitor){
      if(site_visitor!='member'){
        if($(el_id)){
          $(el_id).show();
        }
      }
      else{
        //this fixes breadcrumb div position
        if($('breadcrumb-photo')){
          $('breadcrumb-photo').setStyle({'top': '260px'});
        }
      }
    }
  }
  catch(e){
  }
 }
 
 /**
  * fixed breadcrumb nav for photogallery 
  */ 

 function photoGalleryBreadcrumbFix(){
  try{
    if(site_visitor && site_visitor=='member'){
      if($('breadcrumb-photo')){
        $('breadcrumb-photo').setStyle({'top': '275px'});
      }
    }
  }
  catch(e){
  }
 }
 
 /**
  * DART tags generator
  * @param Integer
  * @param String
  * @return void       
  */ 
  
  function dartTagGen(sz,pos){
    try{
      if(site_visitor && site_visitor!='member'){
        document.write(unescape("%3Cscr"+"ipt src='http://ad.doubleclick.net/adj/prnd/prn-coast;prngenre=talk;prntype=web;pos="+ pos +";sz="+ sz +"ord="+ pagepos +"?' type='text/javascript'%3E%3C/scr"+"ipt%3E"));
      }
    }
    catch(e){
    }
  }



//show spotlight control begin

 var spotlightTimer = null;
 var spotlightQueue = [];
 var spotlighCurrentIndex = 0;
 
 /**
  * initializes spotlight
  */
  
 function showSpotlightInit(){
	$("div[id*='modfull_']").each(function(i){
		$(this).css('z-index',1);
	});

	$('#slarrow_1').css('visibility','visible');
	$('#modsm_1').addClass('spotlight-box-selected');
	$('#modsm_1').fadeIn('normal');
 	$('#modfull_1').fadeIn('normal');
 	
 	//run animation once - change arr length to 2 if needed
 	
 	$("div[id*='modfull_']").each(function(){
		var arr = $(this).attr('id').split('_');
		if(!arr || !arr.length || arr.length!=1){
			return;
		}
		var mod_id = parseInt(arr[1]);
		spotlightQueue.push(mod_id);
	});
 	
	spotlightTimer = setInterval('showSpotlightAnimate()',1000);
 }
 
 /**
  * iterates once thru spotlight modules
  */
 
 function showSpotlightAnimate(){
 	if(spotlightQueue && spotlightQueue.length>0){
 		if(spotlighCurrentIndex>(spotlightQueue.length-1)){
 			spotlighCurrentIndex = 0;
 			showSpotlightSwap(spotlightQueue[spotlighCurrentIndex]);
 			clearInterval(spotlightTimer);
 			return;
 		}
 		showSpotlightSwap(spotlightQueue[spotlighCurrentIndex]);
 		//update interval
 		if(spotlighCurrentIndex==0){
 			clearInterval(spotlightTimer);
 			spotlightTimer = setInterval('showSpotlightAnimate()',4000);
 		}
 		spotlighCurrentIndex++;
 	}
 }
 
 /**
  * swaps full and preview blocks
  */
  
 function showSpotlightSwap(mod_id){
	if(!mod_id){
		return;
	}
	var total_blocks = 4;
	$('#modsm_' + mod_id).addClass('spotlight-box-selected');
	$('#modfull_' + mod_id).fadeIn('normal');
	$('#slarrow_' + mod_id).css('visibility','visible');
	for(var i=1;i<=total_blocks;i++){
		if(i==mod_id){
			continue;
		}
		$('#modfull_' + i).fadeOut('normal');
		$('#slarrow_' + i).css('visibility','hidden');
		$('#modsm_' + i).removeClass('spotlight-box-selected');
	}
 }
 
 /**
  * main control function for spotlight section
  */
 
 function showSpotlightControl(){
	 try{
	 	showSpotlightInit();
	 	$("div[id*='modsm_']").click(
	 		function(){
				//alert('clicked');
				clearInterval(spotlightTimer);
				var arr = $(this).attr('id').split('_');
				if(!arr || !arr.length || arr.length!=2){
					return;
				}
				var id = parseInt(arr[1]);
				showSpotlightSwap(id);
			}
	 	);
	 }
	 catch(e){
	}
 }

