/* Author: Adam Savitzky

*/

$(function (){
	var dropdown = {
		config: {
			speed: 100,
			container: $("#globalNav"),
			listClass: false,
			useHoverIntent: true
		},
		init: function (config) {
			$.extend(dropdown.config, config);
			dropdown.$container = dropdown.config.container;
			dropdown.$sections = (dropdown.config.listClass) ?
				dropdown.$container.find("li."+dropdown.config.listClass) :
				dropdown.$container.find("li");
			(dropdown.config.useHoverIntent) ?
				dropdown.$sections.hoverIntent(hoverIntentConfig) :
				dropdown.$sections.hover(dropdown.showItem, dropdown.showItem);
		},
		showItem: function() {
			$(this).addClass("sfhover").find("ul:first").slideDown(dropdown.config.speed);
		},
		hideItem: function () {
			$(this).removeClass("sfhover").find("ul:first").hide();
		}
	};
	
	var hoverIntentConfig = {
		over: dropdown.showItem,
		out: dropdown.hideItem,
		timeout: 10,
		interval: 75,
		sensitivity: 7
	};
	
	dropdown.init(hoverIntentConfig);
	
	$('.sim_store').isotope({
      // options
      itemSelector : '.sim',
      layoutMode : 'fitRows'
    });
    
    $(".sim_store .sim").click(function () {
        setTimeout(function () {
            $(".sim_store").isotope("reLayout");
        }, 500)
        $(this).toggleClass("expanded").siblings().removeClass("expanded");
    })
    
    $(".sim_store .sim .details a").click(function (e) {
        e.stopImmediatePropagation();
        //return false;
    });

    $(".filters input").change(function () {
        var selector = "";
        
        if ($(this).val() === "*") {
            selector = "*"
            $(".filters input[class!='filter-all']").removeAttr("checked");
        } else {
            $(".filter-all").removeAttr("checked");
            
            $(".filters input").each(function () {
                if ($(this).is(':checked')) {
                    selector += $(this).val() + ", ";
                }
            });
        }
        
        $(".sim_store").isotope({ filter: selector});
    });

    
    VideoJS.setupAllWhenReady();
    
    $("#signUp").click(function () {
        window.location = "/simulate/home/";
    })
    
    //stick the footer at the bottom of the page if we're on an iPad/iPhone due to viewport/page bugs in mobile webkit
    if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') {
         $("footer").css("position", "static");
    };
    
    $(".button[href]").click(function () {
        var href = $(this).attr("href");
        
        if (href) {
            window.location = href;
        }
    });
    
    $(".datepicker").datepicker();
    
    $("form .button").click(function () {
        $(this).parent("form").submit();
    });
    
    $("*").tooltip();
});




























