/**
* Styleswitch stylesheet switcher built on jQuery
* Under an Attribution, Share Alike License
* By Kelvin Luck ( http://www.kelvinluck.com/ )
**/

(function($) {
$(document).ready(function() {



if ($.browser.msie && $.browser.version <= 7) {
var zIndexNumber = 10000;
	$('li').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 1;
	});
}

$(".loader").animate({opacity: "0"}, 1000);	




// Show More when clicked
		$('a.more').click(function() {
			var id = this.getAttribute("id");
			var id_pieces = id.split('_');
			if (id_pieces.length==2)
			{
				var more_id = 's_'+id_pieces[1];
				//alert(more_id);
				$(this).text($(this).text() == 'More' ? 'Less' : 'More');
				$(this).toggleClass('expanded');
				$('ul#'+more_id).slideToggle("slow");
			}
			
			return false;	
		});


/*
--------------------------------------------------------------------------------------- QUICKIES
*/	

  $('div.q_block > div.q_secondary').hide();
  $('div.q_block > h3').click(function() {
  	 $('div.q_block > h3').removeClass();
  	 $('div.q_block > div').slideUp('fast');
	 $(this).next().next('div').fadeToggle('fast');
	 $(this).addClass('on');
  });
  
  $('a.close').click(function(){
  	$(this).parent().parent().slideToggle('fast');
  	$('div.q_block > h3').removeClass();
  	return false;
  });
  

	jQuery.fn.fadeToggle = function(speed, easing, callback) {
		return this.animate({opacity: 'toggle'}, speed, easing, callback);
	};

/*
--------------------------------------------------------------------------------------- STYLE SWITCHER
*/

//$.cookie("style", "light", { expires: 7 }); // Sample 2

$('a.styleswitcher').styleSwitcher();

/* style-switcher.php?style=dark */

$('a.styleswitcher').click(function() {
	var mystyle = $.cookie('style');
	if (mystyle == "dark") {
		$(this).attr('href','style-switcher.php?style=light');
		$.cookie("style", "light", { expires: 7 }); // Sample 2
	} else {
		$(this).attr('href','style-switcher.php?style=dark');	
		$.cookie("style", "dark", { expires: 7 }); // Sample 2
	}
	
});

/* Detects iDevices */


/*
var deviceAgent = navigator.userAgent.toLowerCase();
var agentID = deviceAgent.match(/(ipad)/);
if (agentID) {
 $('a').live('touchend', function(e) {
    var el = $(this);
    var link = el.attr('href');
    window.location = link;
});

 
}
*/

/*
--------------------------------------------------------------------------------------- INVIEW
*/

 var topRange      = 200,  // measure from the top of the viewport to X pixels down
     edgeMargin    = 20,   // margin above the top or margin from the end of the page
     animationTime = 1200, // time in milliseconds
     contentTop = [];
     
 // Set up content an array of locations
 $('nav ul').find('a').each(function(){
  contentTop.push( $( $(this).attr('href') ).offset().top );
 })

 
 // adjust side menu
 $(window).scroll(function(){
  var winTop = $(window).scrollTop(),
      bodyHt = $(document).height(),
      vpHt = $(window).height() + edgeMargin;  // viewport height + margin
  $.each( contentTop, function(i,loc){
   if ( ( loc > winTop - edgeMargin && ( loc < winTop + topRange || ( winTop + vpHt ) >= bodyHt ) ) ){
    $('nav li a')
     .removeClass('on')
     .eq(i).addClass('on');
   }
  })
 })


/* EVERYTHING ABOVE THIS LINE */




});
		
})(jQuery);  
/*
--------------------------------------------------------------------------------------- End Jquery wrapper
*/
