$(document).ready(function(){

	// =====================================================================================
	// App wide
	// =====================================================================================
	// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  // Rollovers
  $("a.rollover").hover(
    function() {
      curr = $(this).find("img").attr("src");
      overlen = curr.length;
      over = curr.substr(0, overlen-4);
      over = over+'_on.png';
      $(this).find("img").attr({ src: over});
    },
    function() {
      $(this).find("img").attr({ src: curr});
    }
  )
	// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  // Rollovers - Preload images
  $("a.rollover").find("img").each(function(i){
    temp = this.src;
    prelen = temp.length;
    pre = temp.substr(0, prelen-4);
    pre = pre+'_on.png';
    preload_image_object = new Image();
    preload_image_object.src = pre;
  });

	// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	// Superfish Drop navbar
  $('ul.sf-menu').superfish({ 
      delay:       200,         // one second delay on mouseout 
      speed:       'fast',      // faster animation speed 
      autoArrows:  false,       // disable generation of arrow mark-up 
      dropShadows: false        // disable drop shadows 
  });


	// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	// Navbar Fades
	// control hover in/out fade speed
	var hoverSpeed = 300;
	// remove link background images since we're re-doing the hover interaction below 
	// (doing it this way retains the CSS default hover states for non-javascript-enabled browsers)
	$("ul.sf-menu li").children("a").css({backgroundImage:"none"});
	
	
	// toggle colour bar shift on hover of nav items
	attachNavEvents("portfolio", "deco1");
	attachNavEvents("services", "deco2");
	attachNavEvents("about", "deco3");

	function attachNavEvents(id, classId) {
		$("ul.sf-menu ." + id).mouseover(function() {
			// create pseudo-link and fade it in
			$(this).before('<div class="nav-' + id + '"></div>');
			$("div.nav-" + id).css({display:"none"}).fadeIn(hoverSpeed);
			// create colourbars and fade them in
			$("#container .wrap").prepend('<i class="' + classId + '"></i>');
			$("." + classId).css({display:"none"}).fadeIn(hoverSpeed);
		}).mouseout(function() {
			// fade out & destroy pseudo-link
			$("div.nav-" + id).fadeOut(hoverSpeed, function() {
				$(this).remove();
			});
			// fade out & destroy colourbars
			$("i." + classId).fadeOut(hoverSpeed, function() {
				$(this).remove();
			});
		});
	}
	
	


});
