/* Author:

*/


/* Option menu for mobile devices
================================================== */

	 $(function() {
	   
      // Create the dropdown base
      $("<select />").appendTo("nav#nav-main");
      
      // Create default option "Go to..."
      $("<option />", {
         "selected": "selected",
         "value"   : "",
         "text"    : "Meny »"
      }).appendTo("nav#nav-main select");
      
      // Populate dropdown with menu items
      $("nav#nav-main a").each(function() {
       var el = $(this);
       $("<option />", {
           "value"   : el.attr("href"),
           "text"    : el.text()
       }).appendTo("nav#nav-main select");
      });
      
	   // To make dropdown actually work
	   // To make more unobtrusive: http://css-tricks.com/4064-unobtrusive-page-changer/
      $("nav#nav-main select").change(function() {
        window.location = $(this).find("option:selected").val();
      });
	 
	 });





/* Flex Slider
================================================== */
$(window).load(function() {
$('.flexslider').flexslider({

animation: "slide",              //Select your animation type (fade/slide)
slideshow: true,                //Should the slider animate automatically by default? (true/false)
slideshowSpeed: 7000,           //Set the speed of the slideshow cycling, in milliseconds
animationDuration: 500,         //Set the speed of animations, in milliseconds
directionNav: false,             //Create navigation for previous/next navigation? (true/false)
controlNav: true,               //Create navigation for paging control of each clide? (true/false)
keyboardNav: true,              //Allow for keyboard navigation using left/right keys (true/false)
touchSwipe: true,               //Touch swipe gestures for left/right slide navigation (true/false)
prevText: "Previous",           //Set the text for the "previous" directionNav item
nextText: "Next",               //Set the text for the "next" directionNav item
pausePlay: false,               //Create pause/play dynamic element (true/false)
randomize: false,               //Randomize slide order on page load? (true/false)
slideToStart: 0,                //The slide that the slider should start on. Array notation (0 = first slide)
animationLoop: true,            //Should the animation loop? If false, directionNav will received disabled classes when at either end (true/false)
pauseOnAction: true,            //Pause the slideshow when interacting with control elements, highly recommended. (true/false)
pauseOnHover: false,            //Pause the slideshow when hovering over slider, then resume when no longer hovering (true/false)
controlsContainer: ".flex-container",          //Advanced property: Can declare which container the navigation elements should be appended too. Default container is the flexSlider element. Example use would be ".flexslider-container", "#container", etc. If the given element is not found, the default action will be taken.
manualControls: "",             //Advanced property: Can declare custom control navigation. Example would be ".flex-control-nav" or "#tabs-nav", etc. The number of elements in your controlNav should match the number of slides/tabs (obviously).
start: function(){},            //Callback: function(slider) - Fires when the slider loads the first slide
before: function(){},           //Callback: function(slider) - Fires asynchronously with each slider animation
after: function(){},            //Callback: function(slider) - Fires after each slider animation completes
end: function(){}               //Callback: function(slider) - Fires when the slider reaches the last slide (asynchronous)
    
});
});






/* Tabs Activiation
================================================== */

	var tabs = $('ul.tabs');

	tabs.each(function(i) {

		//Get all tabs
		var tab = $(this).find('> li > a');
		tab.click(function(e) {

			//Get Location of tab's content
			var contentLocation = $(this).attr('href');

			//Let go if not a hashed one
			if(contentLocation.charAt(0)=="#") {

				e.preventDefault();

				//Make Tab Active
				tab.removeClass('active');
				$(this).addClass('active');

				//Show Tab Content & add active class
				$(contentLocation).show().addClass('active').siblings().hide().removeClass('active');

			}
		});
	});





/* Scroll to top
================================================== */

$(document).ready(function(){
    $(".scroll").click(function(event){
        //prevent the default action for the click event
        event.preventDefault();
 
        //get the full url - like mysitecom/index.htm#home
        var full_url = this.href;
 
        //split the url by # and get the anchor target name - home in mysitecom/index.htm#home
        var parts = full_url.split("#");
        var trgt = parts[1];
 
        //get the top offset of the target anchor
        var target_offset = $("#"+trgt).offset();
        var target_top = target_offset.top;
 
        //goto that anchor by setting the body scroll top to anchor top
        $('html, body').animate({scrollTop:target_top}, 550);
    });
});





/* Lightbox gallery
================================================== */

$(document).ready(function() {
	$(".gallery-item a").attr('rel', 'gallery').fancybox({
		'titlePosition'		: 'outside',
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.9
	});
});






