// Clear Search box text on focus only if default text is present
$(function() {
	$('#Search .query').focus(function() {
		if (this.value=="Search...") {
			this.value = "";
		}
	});
	$('#Search .query').blur(function() {
		if (this.value=="") {
			this.value = "Search...";
		}
	});
});

var DD_belatedPNG;
if (DD_belatedPNG) { // Only execute for IE6
	// Selectors need to match what's in the CSS exactly
	DD_belatedPNG.fix('ul li a.html img');
	DD_belatedPNG.fix('#footer .fourCol ul li a.facebook, #footer .fourCol ul li a.linkedIn, #footer .fourCol ul li a.twitter, #footer .fourCol ul li a.blog');
	DD_belatedPNG.fix('#Search .query, #footer ul.links li, div.bluetabs LI A');
	DD_belatedPNG.fix('#calloutContainer ul.socialMedia li a, #calloutContainer ul.resourceLibrary li a');
	DD_belatedPNG.fix('#calloutContainer ul.partners li');
	DD_belatedPNG.fix('#contentContainer .banner a.login');
}


/* Carousel for homepage spotlight */
var HomeSpotlightCarousel = {
    carousel: null,
    paused: false,
    clicked: 0,
    init: function() {
        $('#HomeSpotlightCarousel').each(function(i) {
            $(this).find('li.hideOnLoad').removeClass('hideOnLoad').css({opacity: .001});
            $(this).jcarousel({
                // auto: 5,
                wrap: 'last',
                visible: 1,
                scroll: 1,
                itemVisibleInCallback: HomeSpotlightCarousel.itemVisibleInCallback,
								//itemVisibleOutCallback: HomeSpotlightCarousel.itemVisibleOutCallback,
                animation: 0
            });
        });
    },
    /* Called when the image/slide loads. First it fades in the new image, then
        it uses jQuery's animate function to delay before fading out the image.
        Once the image has faded out there is a callback to tell the carousel
        to transition to the next slide/image and the process starts over again.
    */
    itemVisibleInCallback: function(c, el, i, state) {
      $(el).fadeTo('slow', 1.0, function() { HomeSpotlightCarousel.fadeInCallback(c, el, i, state); });
    },
		//itemVisibleOutCallback: function(c, e1, i, state) {
		//	$(el).fadeTo('slow', .001, function() { HomeSpotlightCarousel.fadeInCallback(c, el, i, state); });
		//},
		fadeInCallback: function(c, el, i, state) {
        setTimeout(function() {
            $(el)
                     // Must animate almost to 0, cause if we go to 0, then the element
                    // gets display="none" and it auto switches to the next slide
                    .fadeTo('slow', 0.001, function() {
                            c.next();
                    } );
        }, 8000);
    }
};
$(document).ready(HomeSpotlightCarousel.init);

// prettyPhoto plugin
$(document).ready(function(){
	$("a[rel^='prettyPhoto']").prettyPhoto({theme: 'light_rounded'});
});

function getParameterByName( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

// Precise Demo Video 
var VideoModal = {
	init: function() {
		$('a.preciseDemo').bind('click', VideoModal.triggerPreciseVideoClick);
	},
	triggerPreciseVideoClick: function(e) {
		if (navigator.platform == "iPad" || navigator.platform == "iPod" || navigator.platform == "iPhone") {
			return true;
		}
		e.preventDefault();
		$("#Modal").removeAttr('id');
		_gaq.push(['_trackPageview', "/assets/video/demo/index.html"]);
		$ModalContainer = $('<div id="ModalContainer" />').hide();
		$('body').append($ModalContainer);
			
		load_page = '/assets/video/tpm-overview/index.html #VideoContainer';
		$ModalContainer.load(load_page, function() {
			$ModalContainer.dialog({
				autoOpen: false,
				height: 598,
				width: 996,
				title: 'Precise Demo',
				modal: true,
				draggable: false,
				resizable: false,
				close: function(event, ui) {
					VideoModal.closeVideo('.ui-dialog');
				}
			}).dialog('open');
			if (!! document.createElement('video').canPlayType)
			{
				var video = $('#VideoContainer').find('video').get(0);
				if (video)
					setTimeout(function() { video.play(); }, 500);
			} 
		});
	},
	closeVideo: function(videoContainer) {
		var $$ = $(videoContainer);
		$$.remove();
	}
};
$(document).ready(function() {
	VideoModal.init();
});

//SYNTAX: tabdropdown.init("menu_id", [integer OR "auto"])
tabdropdown.init("bluemenu");

