/*********************************

	global.js for Flawless Marketing
	code by Matt Benning (matt@sympl.ca)

*********************************/

/* ON PAGELOAD, DO THIS STUFF */
$(document).ready(function(){

  // popup windows
  $("a.popup").popupwindow();

  // show/hide plan details
  $('.plan-detail h2 a').click(function(){
    if( $(this).is('.contracted') ){
      $('../../div:first',this).show();$(this).removeClass('contracted');$(this).addClass('expanded');
    }else{
      $('../../div:first',this).hide();$(this).removeClass('expanded');$(this).addClass('contracted');
    }
    return false;
  });
  
  // show/hide comparison matrix table rows
  $('#comparison-matrix tbody th a').click(function(){
    var target = $(this).attr('rel');
    if( $(this).is('.contracted') ){
      $('#'+target).show();$(this).removeClass('contracted');$(this).addClass('expanded');
    }else{
      $('#'+target).hide();$(this).removeClass('expanded');$(this).addClass('contracted');
    }
    return false;
  });
  
  // show 'subject: other' field for email form
  $('#frmEmail #subject').change(function(){
    var messageIndex;
    messageIndex=$('#subject').val();
    if (messageIndex=='other'){
      $('#other').show();
    }else{
      $('#other').hide();
    }
  });
  
  // show regional offices on contact page
  $('#contact #region').change(function(){
    var messageIndex;
    messageIndex=$('#region').val();
    if (messageIndex=='wa'){
      $('#washington').show();
      $('#oregon').hide();
    }else if (messageIndex=='or'){
      $('#oregon').show();
      $('#washington').hide();
    }
  });
  
  // show google maps
  $('#contact .location a').click(function(){
    var target = $(this).attr('rel');
    $('select').toggle();
    $('#'+target).toggle();
    return false;
  });
  
  // zebra striping on contact us page
  $('#contact .chunk:odd').addClass('alt');
  
});









/*
Popupwindow plugin for jQuery.
by: Tony Petruzzi
homepage: http://rip747.wordpress.com
plugin download: http://rip747.wordpress.com/2007/03/02/the-return-of-popupwindow-jquery-plugin/
  
Takes a link and will create a popupwindow based on the href of the link. You can
over ride the default setting by passing your own settings using the REL attribute
of the link. You can have different setting for each link if you'd like.
   
To use just include the plugin in the HEAD section of the page AFTER calling jQuery.
After that, use jQuery to find the links you want and pass any parameters you want

04/04/2007:

1) added profiles so you don't have to pass the settings for each link anymore.
2) remove resize as a setting and add the correct setting resizable
3) removed example text from this file and made an index.htm files to house example.
4) add example of using profiles to the new examples page.
5) example pulls the latest jquery library from jquery.com.

05/14/2007

1) removed trailing comma in settings that was causing IE to bottom out with an error.

*/

jQuery.fn.popupwindow = function(p)
{

	var profiles = p || {};

	return this.each(function(index){
		var setting, parameters, mysettings, b, a;
		
		// for overrideing the default settings
		mysettings = (jQuery(this).attr("rel") || "").split(",");

		
		settings = {
          height:600, // sets the height in pixels of the window.
          width:600, // sets the width in pixels of the window.
          toolbar:0, // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
          scrollbars:0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
          status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
          resizable:1, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
          left:0, // left position when the window appears.
          top:0, // top position when the window appears.
          centerv:0, // should we center the window vertically? {1 (YES) or 0 (NO)}. overrides top
          centerh:0, // should we center the window horizontally? {1 (YES) or 0 (NO)}. overrides left
          location:0, // show the location box with the current url (The place to type http://address) {1 (YES) or 0 (NO)}.
          directories:0, // show the extra buttons. (what's cool, personal buttons, etc...) {1 (YES) or 0 (NO)}.
          menubar:0, //show the menus at the top of the window (File, Edit, etc...) {1 (YES) or 0 (NO)}.
          copyhistory:0 //copy the old browser window's history list to the new window {1 (YES) or 0 (NO)}.
		};

		// if mysettings length is 1 and not a value pair then assume it is a profile declaration
		// and see if the profile settings exists


		if(mysettings.length == 1 && mysettings[0].split(":").length == 1)
		{
			a = mysettings[0];
			// see if a profile has been defined
			if(typeof profiles[a] != "undefined")
			{
				settings = jQuery.extend(settings, profiles[a]);
			}
		}
		else
		{
			// overrides the settings with parameter passed in using the rel tag.
			for(var i=0; i < mysettings.length; i++)
			{
				b = mysettings[i].split(":");
				if(typeof settings[b[0]] != "undefined" && b.length == 2)
				{
					settings[b[0]] = b[1];
				}
			}
		}

		// center the window vertically
		if (settings.centerv == 1)
		{
			settings.top = (screen.height-(settings.height + 110))/2;
		}
		
		// center the window horizontally
		if (settings.centerh == 1)
		{
			settings.left = (screen.width-settings.width)/2;
		}
		
		parameters = "height=" + settings.height + ",width=" + settings.width + ",toolbar=" + settings.toolbar + ",scrollbars=" + settings.scrollbars  + ",status=" + settings.status + ",resizable=" + settings.resizable + ",left=" + settings.left  + ",screenX=" + settings.left + ",top=" + settings.top  + ",screenY=" + settings.top;
		
		jQuery(this).bind("click", function(){
			var name = "PopUpWindow" + index;
			window.open(this.href, name, parameters).focus();
			return false;
		});
	});

};
