  var id = "";
	
	function resize(){
		var page_height = $(window).height();
		var footer_height = 45;
		var header_height = 130;
		$("#s_content").css("height", page_height- (footer_height + header_height));
	}
	
	//update the content width on page resize
  $(window).bind("resize", function() {
    $("#level_1_divs, #work-jibe").width($(window).width() + "px");
    $("#level_1_divs, #about-people-jibe").width($(window).width() + "px");
    $(".whitebar").width($(window).width() - 919 + "px");
  });
		
	$(function(){
		
		$(window).resize(function(){
				//resize();
		});
		
    $('a[href=#open]').live("click", function(event) {
      event.preventDefault();
      $("#footer_links_sm").css("display", "none");
      $("#footer_contact").css("display", "block");
      $('#s_footer').animate({
        height: '365px'
      }, {
        duration: 500, 
        specialEasing: {
          height: 'linear'
        },
        complete: function(){
          $('a[href=#open] img').attr("src", "images/template/footer_close.gif");
          $('a[href=#open]').attr("href", "#close");          
        }
      });
    });
    
    $('a[href=#close]').live('click', function(event) {
      event.preventDefault();
      $("#contact_bubble").css('display', "none");
      $('#s_footer').animate({
        height: '45px'
      }, {
        duration: 500, 
        specialEasing: {
          height: 'linear'
        },
        complete: function(){
          $('a[href=#close] img').attr("src", "images/template/footer_open.gif");
          $('a[href=#close]').attr("href", "#open");
          $("#footer_links_sm").css("display", "block");
          $("#footer_contact").css("display", "none");
        }
      });
    });
      
      $("input#text").live("click", function(){
        if($(this).val() == "yourname@email.com"){
          $(this).val("");
        }
      });
      
      $("input.text").blur( function(){
        if($(this).val() == ""){
          $(this).val("yourname@email.com");
        }
      });
      
      $("#footer_jibe, #contact_bubble").live("mouseenter", function(event){
          $("#contact_bubble").css('display', "block");
      });
			
      $("#footer_map").live("mouseleave", function(event){
					$("#contact_bubble").css('display', "none");
      });
			
			$("#contact_holder .content, .contact_bubble").live("mouseenter", function(event){
          $(".contact_bubble").css('display', "block");
      });
			
      $("#contact_holder .content").live("mouseleave", function(event){
					$(".contact_bubble").css('display', "none");
      });
			
			$.fn.cycle.transitions.jibe = function(cont, slides, opts) {
				
				var el = $(slides[0]);
				var w = el.width(); 
				var h = el.height();
				var sections = id.split('-');
				if(sections.length == 1){
					opts.cssBefore = { top: '100%' },
					opts.animIn  = { top:'0', opacity:1 },
					opts.animOut   = { top:'-100px', opacity:0 },
					opts.cssAfter = { left: '0', top:0}
				}
				else{
					opts.cssBefore = { left: '480px' },
					opts.animIn    = { left:'0px', opacity:1},
					opts.animOut   = { left:'-200px', opacity:0 }
					opts.cssAfter = { left: '0px'}
				}
				opts.before.push(function(curr, next, opts, fwd) {
					$.fn.cycle.commonReset(curr,next,opts);
					opts.cssBefore.up = fwd ? (next.cycleW-1) : (1-next.cycleW);
					opts.animOut.up = fwd ? -curr.cycleW : curr.cycleW;
					
			  });
			};
			
			$('#level_1_divs').cycle({ 
				fx: 'jibe',
				timeout:0,
				pager: '.hidden',
				speedIn: 1500,
				speedOut:1000,
				pagerAnchorBuilder: function(idx, slide) {
				  slide_id = slide.id;
				  slide_id = slide_id.replace('-jibe', '');
				  return '<li><a href="#' + slide_id + '-div" class="'+ slide_id +'-main ">' + slide_id + '</a></li>'; 
				}
			});	
			
			$("a#s_logo, a.backhome").click(function(event){
			  //event.preventDefault();
				id = 'home';
				$("a.home-main").click();
				$("#continue-right").css("display", 'none');
				$(".main").css("display", 'block');
				$(".main-active").css("display", 'none');
				$(".sub_page-active").css("display", 'none');
			});
			
			$("a[href=#blog]").click(function(event){
				event.preventDefault();
				window.location = 'http://blog.jibemedia.com/';
			});
			
			$("a.main").click(function(event){
				//event.preventDefault();
				id = $(this).parent('li').attr('id').replace('-jibe', '');
				
				$.post(BASEDIR + "/ajax/get_page.php", {'page': id}, function(page){
					//$("#level_1_divs").children("div").html("");
					$("." + id + '-div').html(page.text);
					if(!$.browser.msie) {
					  $("title").html(page.title + " - Jibe Media - Salt Lake City, Utah");
					}
					
					if(splits[0] != hash){
						$(hash+'-jibe').click();
						hash = splits[0];
					}
					
					window.setTimeout(function() {
            $("#level_1_divs").children("div").not("." + id + "-div").html("");
  			  }, 1500);
					
					//$(document).scrollTop(0);
				}, 'json');
				
				$("a." + id + "-main").click();				
				$(".main").css("display", 'block');
				$(this).css("display", 'none');
				$(".main-active").css("display", 'none');
				$(".sub_page-active").css("display", 'none');
				$(this).parent('li').children(".main-active").css("display", 'block');
				$(document).scrollTop(0);
				//customScroll(id);
			});
      
			$("a.sub_page").live('click', function(event){
			  var old_id = id;
			  
				//event.preventDefault();
				id = $(this).attr("id").replace('-jibe', '');
				$.post(BASEDIR + "/ajax/get_page.php", {'page': id}, function(page){
				  window.setTimeout(function() {
				    //$("#level_1_divs").children("div").html("");
    				$("." + id + "-div").html(page.text);
    				if(!$.browser.msie) {
    				  $("title").html(page.title + " - Jibe Media - Salt Lake City, Utah");
    				}
    				$(document).scrollTop(0);
          }, 200);
          
				}, 'json');
				
				window.setTimeout(function() {
          $("#level_1_divs").children("div").not("." + id + "-div").html("");
			  }, 1500);
				
				var parts = id.split('-');
				$("a." + id + "-main").click();
				$(".sub_page-active").css("display", "none");
				$("span#" + id + "-active").css("display", 'none');
				$(".main").css("display", 'block');
				$("li#" + parts[0] + "-jibe a.main").css("display", 'none');
				$(".main-active").css("display", 'none');
				$("#" + parts[0]  + "-jibe #" + id + "-active").css("display", 'block');
				//customScroll(id);
				
				window.location.hash = $(this).attr('href');
				
				$('#s_content').scrollLeft(0);

				return false;
			});
			
			$('#s_content').scroll(function() {
			  $('#s_content').scrollLeft(0);
			});
			
			$("a.back").live('click', function(){
				id = $(this).parent('span').parent('li').attr('id').replace('-jibe', '');
				$.post(BASEDIR + "/ajax/get_page.php", {'page': id}, function(page){
					$("#level_1_divs").children("div").html("");
					$("." + id + '-div').html(page.text);
					if(!$.browser.msie) {
					  $("title").html(page.title + " - Jibe Media - Salt Lake City, Utah");
					}
					//$(document).scrollTop(0);
				}, 'json');
				$("a." + id + "-main").click();
				$(".main").css("display", 'block');
				$("#" + id  + "-jibe .main").css("display", 'none');
				$(this).parent("span").css("display", 'none');
				$("#" + id  + "-jibe .main-active").css("display", 'block');
				$(".sub_page-active").css("display", 'none');
				$(this).parent('li').children(".main-active").css("display", 'block');
			});
			
			$("input#newsletter").click(function(event){
			  
			  event.preventDefault();
			  $.post(BASEDIR + "/forms/newsletter.php", {'email' : $("input#text").val() },
					 function(result){
					  if ( result.valid != undefined){
						$(".footer_newsletter").children("table").children("tbody").children("tr:first").html("<td colspan='2' style='font-size:14px;'>Thank you!</td>");
					  } else {
						$(".footer_newsletter").children("table").children("tbody").children("tr:first").children("td:nth-child(1)").children("input").after("<p style='font-size:14px;'>Please enter a valid email.</p>");
					  }
					 }, 'json');
			  
			})
		
    });
	
	var hash = window.location.hash;
	var splits;
	$(document).ready(function(){
		if(hash != ''){ $("#home").css("display", 'none'); }
		splits = hash.split('-', 1);
		$(splits[0]+'-jibe').children('a').click();
	});
	
	
	/**
 * jQuery mousehold plugin - fires an event while the mouse is clicked down.
 * Additionally, the function, when executed, is passed a single
 * argument representing the count of times the event has been fired during
 * this session of the mouse hold.
 *
 * @author Remy Sharp (leftlogic.com)
 * @date 2006-12-15
 * @example $("img").mousehold(200, function(i){  })
 * @desc Repeats firing the passed function while the mouse is clicked down
 *
 * @name mousehold
 * @type jQuery
 * @param Number timeout The frequency to repeat the event in milliseconds
 * @param Function fn A function to execute
 * @cat Plugin
 */

jQuery.fn.mousehold = function(timeout, f) {
	if (timeout && typeof timeout == 'function') {
		f = timeout;
		timeout = 100;
	}
	if (f && typeof f == 'function') {
		var timer = 0;
		var fireStep = 0;
		return this.each(function() {
			jQuery(this).mousedown(function() {
				fireStep = 1;
				var ctr = 0;
				var t = this;
				timer = setInterval(function() {
					ctr++;
					f.call(t, ctr);
					fireStep = 2;
				}, timeout);
			})

			clearMousehold = function() {
				clearInterval(timer);
				if (fireStep == 1) f.call(this, 1);
				fireStep = 0;
			}
			
			jQuery(this).mouseout(clearMousehold);
			jQuery(this).mouseup(clearMousehold);
		})
	}
}

