// Navigation Menu
var timeout    = 200;
var closetimer = 0;
var ddmenuitem = 0;
var ddmenubtn	 = 0;
var hoverClass = 0;

function jsddm_open()
{	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').css('visibility', 'visible');
	hoverClass = 'n-over-'+$(this).find('.nav-btn').attr('id');
	ddmenubtn = $(this).find('.nav-btn').addClass(hoverClass)}
	
function jsddm_close()
{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
	if(ddmenubtn) ddmenubtn.removeClass(hoverClass)}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
	{  window.clearTimeout(closetimer);
		closetimer = null;}}

$(document).ready(function()
{  $('.nav-main > li').bind('mouseover', jsddm_open)
	$('.nav-main > li').bind('mouseout',  jsddm_timer)});

document.onclick = jsddm_close;

// Video Grid
$(document).ready(function(){
 
	//Hide (Collapse) the toggle containers on load
	$(".video-grid").css("height","121px"); 
	
	$("#more-videos").toggle(
  function () {
		$("#more-videos").html("View Fewer Videos");
		$(".video-grid").animate( { height:"484px" }, "slow" );
  },
  function () {
		$("#more-videos").html("View More Videos");
    $(".video-grid").animate( { height:"121px" }, "slow" );
  }
);
 
});


// Video Grid Domestic
$(document).ready(function(){
 
	//Hide (Collapse) the toggle containers on load
	$(".video-grid-d").css("height","121px"); 
	
	$("#more-videos-d").toggle(
  function () {
		$("#more-videos-d").html("View Fewer Videos");
		$(".video-grid-d").animate( { height:"242px" }, "slow" );
  },
  function () {
		$("#more-videos-d").html("View All");
    $(".video-grid-d").animate( { height:"121px" }, "slow" );
  }
);
 
});

// Video Grid International
$(document).ready(function(){
 
	//Hide (Collapse) the toggle containers on load
	$(".video-grid-i").css("height","121px"); 
	
	$("#more-videos-i").toggle(
  function () {
		$("#more-videos-i").html("View Fewer Videos");
		$(".video-grid-i").animate( { height:"484px" }, "slow" );
  },
  function () {
		$("#more-videos-i").html("View All");
    $(".video-grid-i").animate( { height:"121px" }, "slow" );
  }
);
 
});


// Video Player
$(function() {

	// setup overlay actions to buttons
	$(".v-thumb[rel]").overlay({

		// use the Apple effect for overlay
		effect: 'apple',		
		
		expose: '#474747',				
		
		onLoad: function(content) {
			// find the player contained inside this overlay and load it
			this.getOverlay().find("a.player").flowplayer(0).load();
		},
		
		onClose: function(content) {
			$f().unload();
		}
	});				
	
	// install flowplayers
	$("a.player").flowplayer("swf/flowplayer-3.1.5.swf"); 
});

// Non-Flowplayer Overlay
$(function() {
  $(".nf-overlay[rel]").overlay({
    effect: 'apple',
    expose: '#474747'
	});
  return false;
});

// External Links
$(function(){
    $('a[href^="http://"]:not([href*="www.starkeyhearingfoundation.org"],[href*="www.plan.gs"],.nf-overlay)').click(function(){
        window.open(this.href);
        return false;
    });
});

// Tool Tips
// Define corners and opposites arrays
var corners = [
   'bottomLeft', 'bottomRight', 'bottomMiddle',
   'topRight', 'topLeft', 'topMiddle',
   'leftMiddle', 'leftTop', 'leftBottom',
   'rightMiddle', 'rightBottom', 'rightTop'
];
var opposites = [
   'topRight', 'topLeft', 'topMiddle',
   'bottomLeft', 'bottomRight', 'bottomMiddle',
   'rightMiddle', 'rightBottom', 'rightTop',
   'leftMiddle', 'leftTop', 'leftBottom'
];
var i = 0;

// Create the tooltips only on document load
$(document).ready(function() {
	$('.tip-link').each(function() {
		// If counter reaches maximum, reset
		if(i === corners.length) i = 0;
		
		// Destroy currrent tooltip if present
		if($(this).data("qtip")) $(this).qtip("destroy");
		
		$(this).qtip({
			content: $($(this).attr('href')).html(),
			position: {
				corner: {
					tooltip: corners[i], // Use the corner...
					target: opposites[i] // ...and opposite corner
				}
			},
			style: {
				border: {
					width: 10,
					radius: 10,
					color: '#cae2f3'
				},
				background: '#cae2f3',
				padding: 10,
				textAlign: 'center',
				tip: true // Give it a speech bubble tip with automatic corner detection
			}
		});
		
		i++; // Increase the counter
	});
});

// Default Form Field Values
$(document).ready(function()
{
    $("input[type=text],textarea").focus(function(srcc)
    {
        if ($(this).val() == $(this)[0].title)
        {
            $(this).val("");
        }
    });
    
    $("input[type=text],textarea").blur(function()
    {
        if ($(this).val() == "")
        {
            $(this).val($(this)[0].title);
        }
    });
    
    $("input[type=text],textarea").blur();        
});