$(document).ready(function() {



/*Question/Answer */

  $('p.answer').hide();

  $('.question').live('click', function() {
    $(this).children('p.answer').slideToggle(100);
  });
  
  
/*Sharebar popup */  
  
  $(".open").hover( 
      function () {
        $("> #sharebox", this).fadeIn('fast');
      },
      function () {
        $("> #sharebox", this).fadeOut('fast');
      }
    ); 
  
  

/*Anything Slider*/  
$('#bannerslider')
  .anythingSlider({
   width               : 1016,
   height              : 400,
   startStopped        : false,
   resizeContents      : true,
   buildArrows		   : false,
   hashTags            : false,
   delay               : 5000 
   
  }) 
  
  
  
 $('#home .bannerflip')
    .anythingSlider({
    width               : 285,
    height				 : 240,
    startStopped        : true,
    resizeContents      : true,
    buildNavigation     : false,
    buildArrows		    : true,
    animationTime       : 100
    
    })  
    
 $('#home .logoflip')
    .anythingSlider({
    width               : 980,
    height				 : 70,
    startStopped        : true,
    resizeContents      : true,
    buildNavigation     : false,
    buildArrows		    : true,
    animationTime       : 500,
    theme               : 'logoflip'
    
    })     

/*Colorbox*/  
  
$("a.zoom").colorbox({
transition:"elastic",
scrolling: "false"

});
  

function prepform(){ 
    $("form").ajaxForm({success: 
    function(html){ 
        $.fn.colorbox({html:html, open:true}); 
    } 
    }); 
} 

$(".formzoom").colorbox({
href:"form.html",
width:"740"
}, 
prepform);    

  
/*Infotip*/  
  
$(".logoblockgrid li").hover(function() {
  $(this).children("div.infotip").animate({opacity: "show", left: "118"}, "fast");
}, function() {
  $(this).children("div.infotip").animate({opacity: "hide", left: "128"}, "fast");
});


/*Tell Friend Email Popup and Email Subscribe Popup*/  

$('#tellfriend').hide();
	$('.open a.emailshare, #tellfriend a.close').click(function() {
  $("#tellfriend").toggle();
});

$('#sidebar .emailsubscribebox').hide();
	$('#sidebar .blog-section a.email, #sidebar .emailsubscribebox a.close').click(function() {
  $("#sidebar .emailsubscribebox").toggle();
});




/*Form Inline Labels */

$.fn.setCursorPosition = function(pos) {
	if ($(this).get(0).setSelectionRange) {
		$(this).get(0).setSelectionRange(pos, pos);
	} else if ($(this).get(0).createTextRange) {
		var range = $(this).get(0).createTextRange();
		range.collapse(true);
		range.moveEnd('character', pos);
		range.moveStart('character', pos);
		range.select();
	}
}


	// grab all of the cells that are "lablels" - skips those that are empty or contain only and &nbsp;
	var regex = /^(\s|&nbsp;)*$/;
	var labels = $('.ContactFormItems td').not('.ContactFormItems td:has(input, textarea)').filter(function(){ 
		if(regex.test($.trim($(this).text()))) { return false; } else { return $(this); }
	});
	//console.log(labels);
	
	
	labels.each(function (i) {
		$(this).wrapInner('<label />'); // wrap these elements with actual labels!
		var labelText = $.trim($(this).text());
		$(this).next('td').children('input').attr("value",labelText);
		$(this).next('td').children('textarea').text(labelText);
		$(this).hide();
	});
	
	$(".ContactFormItems input:text").focus(function() {
		if($.trim($(this).parents().prev("td").children('label').html()) == this.value){
			$(this).addClass("focus").setCursorPosition(0);
		}
	});
	$(".ContactFormItems input:text").keypress(function() {
		if($.trim($(this).parents().prev("td").children('label').html()) == this.value){
			this.value = "";
			$(this).removeClass("focus").addClass("typing");
		}
	});
	$(".ContactFormItems input:text").blur(function() {
		$(this).removeClass("focus typing");
		if(this.value == ""){
			this.value = $.trim($(this).parents().prev("td").children('label').html());
		}
	});
	
	$(".ContactFormItems textarea").focus(function() {
		if($.trim($(this).parents().prev("td").children('label').html()) == this.value){
		$(this).addClass("focus").setCursorPosition(0);
	}
	});
	
	$(".ContactFormItems textarea").keypress(function() {
		if($.trim($(this).parents().prev("td").children('label').html()) == this.value){
			this.value = "";
			$(this).removeClass("focus").addClass("typing");
		}
	});
	
	$(".ContactFormItems textarea").blur(function() {
		$(this).removeClass("focus typing");
		if(this.value == ""){
			this.value = $.trim($(this).parents().prev("td").children('label').html());
		}
	});

	// find the submit button row, remove the preceding table cell, make the button cell span 2 columns
  $(".ContactFormItems input:submit").parents().prev("td").remove();
  $(".ContactFormItems input:submit").parent().attr('colspan', 2);
}); /*Close document ready*/




/* Dropdown redirects */
function go() {
	box = document.forms[0].url;
	destination = box.options[box.selectedIndex].value;
	if (destination) location.href = destination;
}


















