$(document).ready(function() {
    // Main navigation
    $("ul.sf-menu").superfish({ 
        pathClass:  'current'
    });
    // 
	var swapValue = [];
	$(".swap-value").each(function(i){
	   swapValue[i] = $(this).val();
	   $(this).focus(function(){
	      if ($(this).val() == swapValue[i]) {
	         $(this).val("");
	      }
	      $(this).addClass("focus");
	   }).blur(function(){
	      if ($.trim($(this).val()) == "") {
	         $(this).val(swapValue[i]);
		 $(this).removeClass("focus");
	      }
	   });
	});
	// Slideshow - right bottom
	$('#pics').after('<div id="ss-nav">').cycle({ 
	    fx:     'fade', 
	    speed:  'slow', 
	    timeout: 5000, 
	    pager:  '#ss-nav' 
	});
	// Expert/Customer quotes - left bottom 
	$("#quote-main ul li:first").addClass('active');
	inHover = function() { 
        var imgDesc = $(this).find('p').html();
        var imgLink = $(this).find('a').attr("href");
        var imgTitle = $(this).find('a').attr("rel");
        $("#quote-main ul li").removeClass('active');
        $(".quote-image a").attr({ href: imgLink });
        $(".quote-image img").attr({ src: imgTitle });
        $(".quote-image p a").html(imgDesc);
    };
    outHover = function () {
        $(this).addClass('active'); 
        return false;
    }
    // Using jQuery hoverIntent plugin - without hover switchs to new link way too fast
	$('#quote-main ul li').hoverIntent(inHover, outHover, {
	    timeout: 500
	});
    // Modal for videos in top 5 questions
    // $.nyroModalSettings();
    $.nyroModalSettings({
      processHandler: function(settings) {
        var from = settings.from;
        if (from && from.href && from.href.indexOf('http://www.youtube.com/watch?v=') == 0) {
          $.nyroModalSettings({
            type: 'swf',
            height: 355,
            width: 425,
            url: from.href.replace(new RegExp("watch\\?v=", "i"), 'v/')+'&autoplay=1'
          });
        }
      }
    });
    $('a.nyroModal').nyroModal();
    $('a.nyroModalText').nyroModal({
        type: 'div',
        height: 300,
        width: 400
    });
    
});
