
$(document).ready(function() {
	
	$('.card.off').hide();
	
	$('.tab a').click(function (e) {
		e.preventDefault();
		var clicked_val = $(this).parent().attr('id').substring(4);
		var card_id = 'card-' + clicked_val;
		
		$(this).parent().parent().find('.tab').removeClass('on');
		$(this).parent().parent().find('.tab').addClass('off');
		$(this).parent().removeClass('off');
		$(this).parent().addClass('on');
		
		$('#' + card_id).parent().find('.card').hide();
		$('#' + card_id).show();
		
		// Hack: google maps get confused when they are hidden
		if ( map !== undefined ) {
			google.maps.event.trigger(map, 'resize');
			map.setZoom( map.getZoom() );
			map.panTo(latlng);
		}
	});

	$('.more-link a').click(function (e) {
		e.preventDefault();
		var dealid = $(this).parent().parent().attr('id');
		$('#' + dealid + ' .more-elipses').hide();
		$('#' + dealid + ' .more-link').hide();
		$('#' + dealid + ' .more-text').show();
		$('#' + dealid + ' .less-link').show();
	});
	
	$('.less-link a').click(function (e) {
		e.preventDefault();
		var dealid = $(this).parent().parent().attr('id');
		$('#' + dealid + ' .more-elipses').show();
		$('#' + dealid + ' .more-link').show();
		$('#' + dealid + ' .more-text').hide();
		$('#' + dealid + ' .less-link').hide();
	});
	
	$('a.pop').click(function(e) {
		e.preventDefault();
		var w = 600;
		var h = 600;
		var settings;
		var LeftPosition;
		var TopPosition;
		var win;
		var link = $(this).attr('href');
		
		LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
		
		settings = 'height=' + h + ','
			+ 'width=' + w + ','
			+ 'top=' + TopPosition + ','
			+ 'left=' + LeftPosition + ','
			+ 'scrollbars=yes,'
			+ 'resizable=yes,'
			+ 'maximize=yes,'
			+ 'status=no,'
			+ 'toolbar=no,'
			+ 'directories=no,'
			+ 'menubar=no,'
			+ 'location=no';
		  
		win = window.open(link, 'pre', settings);
		win.name = 'name';
		win.focus();
	});
	
});

// used for top nav menus
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


opera = (navigator.userAgent.indexOf('Opera') >= 0)? true : false;
ie = (document.all && !opera)? true : false;
dom = (document.getElementById && !ie && !opera)? true : false;

var expiration = new Date();
expiration.setTime(expiration.getTime() + 3600*3600*3600);

function showtranscriptf(elemId,displayValue) {
   name = 'img'+ elemId;
   site_url = "http://dev.gotahoenorth.com/";

  if (dom) {

      if (displayValue) {
         document.getElementById(elemId).style.display = displayValue;
         if (displayValue == "none") {
            document.getElementById(name).src = site_url+"images/plus.gif";

         } else {
            document.getElementById(name).src = site_url+"images/minus.gif";
         } 


         return 0;
      }

      if (document.getElementById(elemId).style.display == "none") {
         document.getElementById(elemId).style.display = "block";
         document.getElementById(name).src = site_url+"images/minus.gif";

      } else if (document.getElementById(elemId).style.display == "block") {
         document.getElementById(elemId).style.display = "none";
         document.getElementById(name).src = site_url+"images/plus.gif";

      } 
      
  } else if (ie) {

    if (displayValue) {
       document.all[elemId].style.display =  displayValue;
       if (displayValue == "block") {
          document.all[name].src = site_url+"images/filter_minus.gif";
       } else {
          document.all[name].src = site_url+"images/filter_plus.gif";
       }
       return 0;
    }

    if (document.all[elemId].style.display == "block") {
       document.all[elemId].style.display = "none";
       document.all[name].src = site_url+"images/filter_plus.gif";


    } else if (document.all[elemId].style.display == "none") {
      document.all[elemId].style.display = "block";
      document.all[name].src = site_url+"images/filter_minus.gif";

    }

  }
}

function displayf(cookie_name, id) {
    var template_category_cookie;

    template_category_cookie = GetCookie(cookie_name);

    if (template_category_cookie) {
       SetCookie(cookie_name, "1", expiration, "", "","") 
       showtranscriptf(id, 'block');
    } else {
       SetCookie(cookie_name, "", expiration, "", "","") 
       showtranscriptf(id, 'none');
    }

    return true;                            
}

function SetCookie(name, value, expires, path, domain, secure) { 
   var mycookie = name + "=" + escape(value);
   var myexpires = new Date();
   if (value == '' || value == 0){
      if (GetCookie(name))
         expir = -30;
      else
         return ;
   }else
      expir = myexpires.setTime(myexpires.getTime() + 5000);
   mycookie = mycookie + "; myexpires=" + expir;
   document.cookie = mycookie;
}


function onCookieChange(cookie_name, id) {
 
  if (dom) {
      if (document.getElementById(id).style.display == "none") {
         SetCookie(cookie_name, "", expiration, "", "","") 
      } else if (document.getElementById(id).style.display == "block") {
         SetCookie(cookie_name, "1", expiration, "", "","")        
      } 
      
  } else if (ie) {

    if (document.all[id].style.display == "block") {
       SetCookie(cookie_name, "1", expiration, "", "","") 
    } else if (document.all[id].style.display == "none") {
       SetCookie(cookie_name, "", expiration, "", "","") 
    }

  }
}

function GetCookie(name) { 
   var arg = name + "="; 
   var alen = arg.length; 
   var clen = document.cookie.length; 
   var i = 0; 

   while (i < clen) { 
     var j = i + alen; 
     if (document.cookie.substring(i, j) == arg)  return getCookieVal (j); 
     i = document.cookie.indexOf(" ", i) + 1; 
     if (i == 0) break; 
   }
    
   return null; 
} 

function getCookieVal (offset) { 
	var endstr = document.cookie.indexOf (";", offset); 
	if (endstr == -1) endstr = document.cookie.length; 
	return unescape(document.cookie.substring(offset, endstr)); 
} 

function display2(cookie_name, id) {
    var template_category_cookie;

    template_category_cookie = GetCookie(cookie_name);

    if (template_category_cookie) {
       SetCookie(cookie_name, "1", expiration, "", "","") 
       showtranscript2(id, 'block');
    } else {
       SetCookie(cookie_name, "", expiration, "", "","") 
       showtranscript2(id, 'none');
    }

    return true;                            
}

function showtranscript2(elemId,displayValue) {
   name = 'img'+ elemId;
   site_url = "http://dev.gotahoenorth.com/";

  if (dom) {

      if (displayValue) {
         document.getElementById(elemId).style.display = displayValue;
         if (displayValue == "none") {
            document.getElementById(name).src = site_url+"images/plus.gif";

         } else {
            document.getElementById(name).src = site_url+"images/minus.gif";
         } 


         return 0;
      }

      if (document.getElementById(elemId).style.display == "none") {
         document.getElementById(elemId).style.display = "block";
         document.getElementById(name).src = site_url+"images/minus.gif";

      } else if (document.getElementById(elemId).style.display == "block") {
         document.getElementById(elemId).style.display = "none";
         document.getElementById(name).src = site_url+"images/plus.gif";

      } 
      
  } else if (ie) {

    if (displayValue) {
       document.all[elemId].style.display =  displayValue;
       if (displayValue == "block") {
          document.all[name].src = site_url+"images/minus.gif";
       } else {
          document.all[name].src = site_url+"images/plus.gif";
       }
       return 0;
    }

    if (document.all[elemId].style.display == "block") {
       document.all[elemId].style.display = "none";
       document.all[name].src = site_url+"images/plus.gif";


    } else if (document.all[elemId].style.display == "none") {
      document.all[elemId].style.display = "block";
      document.all[name].src = site_url+"images/minus.gif";

    }

  }
}

function viewform(m, w, h, scrol) {
   var scroll = 'yes';
   var settings;
   var LeftPosition;
   var TopPosition;
   var win;

   if (!scrol) scrol = 'no';

   LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
   TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
  
   settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll;

   if (scrol == 'no') settings = settings + ',resizable=no,maximize=no';
   if (scrol == 'yes') settings = settings + ',resizable=yes,maximize=yes';

   settings = settings + ',status=no,toolbar=no,directories=no,menubar=no,location=no';
		      
   win = window.open(m, 'pre', settings);
   win.name = 'name';
   win.focus();
}


