  ////////// BOOKMARK iPHONE APP SCRIPT /////////
  
  /*if ('standalone' in navigator && !navigator.standalone && (/iphone|ipod|ipad/gi).test(navigator.platform) && (/Safari/i).test(navigator.appVersion)) {
    document.write('<link rel="stylesheet" href="..\/..\/css\/add2home.css">');
    document.write('<script type="application\/javascript" src="..\/..\/js\/add2home.js" charset="utf-8"><\/s' + 'cript>');
  }*/
    
  
  ////////// MADS BANNER AD /////////
  
  mads_ad_element_id = "mads_ads";
  mads_type = "test";
  mads_zone_id = "0593825025";
  mads_secret = "E88CBFA567276AB4";
  mads_width_max = 320;
  mads_height_max = 54;
  
  
  ////////// Text clipping script /////////
  /*
  $(document).ready(function() {
    $('.headline').dotdotdot({
      wrapper : 'div',
      ellipsis: '... ',
       wrap    : 'word',
       after   : null,
       watch   : true,
       height  : null,
       tolerance: 0 
    });
  });
  */
  ////////// GEOLOCATION /////////
  
  // Get geolocation
  /*
  enable this when geolocation is ready
  todo: create a flow if the user clicks no on sharing location
  */
  setCookie("canUseCookies", "true", 30);
  if(getCookie("canUseCookies") != null){
	  if(getCookie("tv2WeatherLat") == null && getCookie("tv2WeatherLon") == null){
	    jQuery(window).ready(function(){      
	      navigator.geolocation.getCurrentPosition(handle_geolocation_query);  
	      function handle_geolocation_query(position){  
	        //alert('Lat: ' + position.coords.latitude + ' ' +  'Lon: ' + position.coords.longitude);  
	        setCookie("tv2WeatherLat", position.coords.latitude, 30);
	        setCookie("tv2WeatherLon", position.coords.longitude, 30);
	        location.href = "index.pml?ts="+(new Date().getTime());
	      }   
	    });
	  }
  }
  
  
  // getting the parameter
  function gup( name ){
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
      return "";
    else
      return results[1];
  }
  var pageTypeValue = gup("pageType");
  
  
  ////////// CAROSEL iSCROLL /////////
  
  // Top navigation instans
  var nav_myScroll;
  function nav_loaded() {
    nav_myScroll = new iScroll('nav_wrapper', {
//      snap: true,
      momentum: false,
      hScrollbar: false,  
      onScrollEnd: function () {                      
      }
    }); 
    var pageId = getPageIdFromType(pageTypeValue);
    nav_myScroll.scrollToPage(pageId,0,1);
     
  }
  document.addEventListener('DOMContentLoaded', nav_loaded, false);
  
  function getPageIdFromType(pageType){
    pageId = 0;
    if(pageType == "nyheder"){
      pageId = 0;
    }
    else if(pageType == "sporten"){
      pageId = 0;
    }
    else if(pageType == "finans"){
      pageId = 0;
    }
    else if(pageType == "vejret"){
      pageId = 1;
    }
    else if(pageType == "beep"){
      pageId = 1;
    }
    else if(pageType == "go"){
      pageId = 1;
    }
    return pageId;
  }
  
  ////////// FITING LAYOUT TO DIFFERENT DEVICES /////////
  
  // Set carosel to fit screensize
  $(document).ready(function(){
    $("#wrapper").css('width', $(window).width());
    $("#scroller li").css('width', $(window).width());
    $(".headline").css('width', ($(window).width()-20)); // -20 because of padding
    $("#nav_wrapper").css('width', $(window).width());
    
    // if landscape
    if($(window).width() > $(window).height()){
      $("article.news_item p").css('font-size', '0.9em');
      $(".headline").css('text-align', 'center');
      $(".article_container img").css({'display': 'block' , 'margin': '0 auto'});
      $(".headline_frontpage img").css({'display': 'block' , 'margin': '0 auto'});
      $(".article_headline p").css('text-align', 'center');
      
      // hides slider in landscape mode
      $("#wrapper").css('display', 'none');
      $("#nav").css('display', 'none');
      $(".headline_frontpage").css('display', 'block');
      }
    // Portrait mode
    else{
      $("article.news_item p").css('font-size', '0.9em');
      $(".headline").css('text-align', 'left');
      
      }
  });
  
  // On window resize - resize carosel 
  $(window).resize(function() {
    $("#wrapper").css('width', $(window).width());
    $("#scroller li").css('width', $(window).width());
    $(".headline").css('width', ($(window).width()-20)); // -20 because of padding 
    $("#nav_wrapper").css('width', $(window).width());
  
    // if landscape
    if($(window).width() > $(window).height()){
      $("article.news_item p").css('font-size', '0.7em');
      $(".headline").css('text-align', 'center');
      $(".article_container img").css({'display': 'block' , 'margin': '0 auto'});
      $(".headline_frontpage img").css({'display': 'block' , 'margin': '0 auto'});
      $(".article_headline p").css('text-align', 'center');
      
      // hides slider in landscape mode
      $("#wrapper").css('display', 'none');
      $("#nav").css('display', 'none');
      //Display alternativ slider
      $(".headline_frontpage").css('display', 'block');
      
      }
    // portrait mode
    else{
      // display slider in landscape mode
      $("#wrapper").css('display', 'block');
      $("#nav").css('display', 'block');
      
      // Dont display alternativ slider
      $(".headline_frontpage").css('display', 'none');
      
      $("article.news_item p").css('font-size', '0.7em');
      $(".headline").css('text-align', 'left');
      $(".article_headline p").css('text-align', 'left');
      }
            
    // refresher carosel 
    setTimeout(function () {
      myScroll.refresh();
      myScroll.scrollToPage(currentPage, 0, 1);       
    }, 0);
    
  });

