﻿document.domain="bones.dk";
jQuery(document).ready(function() {
  
  
  // START: Rasturant menu selector  
  jCookieValue=jQuery.cookie("DamngoodCookie");

  var resULs=jQuery(".restaurant_menu");
  jQuery("#restaurant_info li ul").find("li:last-child").addClass("aabning").end().each(function(index,domElm){
    resULs.eq(index).prepend(jQuery(domElm).children());
  });
  Cufon.replace('#sidebar_left #restaurant_box .restaurant_menu li h4', {
    textShadow: '0 1px 0 #fff'
  });
  jQuery("#restaurant_info").remove();
    jQuery("#form_restaurant").after(jQuery("<h2></h2>").addClass("sin-city").css({"margin-left":"30px","text-transform":"uppercase"}));
  if(location.hash.length>1){
    var urlSelectedRes=location.hash.substr(1,1)+location.hash.substring(2);
    jQuery("div#firsttime").css("display","none");
    jQuery("select#select_restaurant option").each(function(){
      if(jQuery(this).text().toLowerCase()===decodeURIComponent(urlSelectedRes).toLowerCase()){
        jQuery(this).attr("selected","selected");
        jQuery.cookie("DamngoodCookie",null);
        jQuery.cookie("DamngoodCookie",jQuery(this).val(),{expires:365,path:"/"});
      }
    })
    jQuery("ul.restaurant_menu").css("display","none");
    jQuery("ul#"+jQuery.cookie("DamngoodCookie")).css("display","block");
    jQuery("#form_restaurant,select#select_restaurant,").css("display","block");
    jQuery(".sin-city").html(document.getElementById("select_restaurant").options[document.getElementById("select_restaurant").selectedIndex].text)
    Cufon.replace(".sin-city");
  }
  else if( jCookieValue != null ) {
    jQuery("div#firsttime").css("display","none");
    jQuery("ul.restaurant_menu").css("display","none");
    jQuery("ul#"+jCookieValue).css("display","block");
    jQuery("#form_restaurant").css("display","block");
    jQuery("select#select_restaurant option[value='"+jCookieValue+"']").attr("selected","selected");
    jQuery(".sin-city").html(document.getElementById("select_restaurant").options[document.getElementById("select_restaurant").selectedIndex].text)
    Cufon.replace(".sin-city");
  }
  else {
    jQuery("div#firsttime").css("display","block").find("a[rel]").each(function(){
      jQuery(this).click(function(){
        jQuery.cookie("DamngoodCookie",null);
        jQuery.cookie("DamngoodCookie",jQuery(this).attr("rel"),{expires:365,path:"/"});
        jQuery("select#select_restaurant option[value='"+jQuery(this).attr("rel")+"']").attr("selected","selected");
        jQuery(".sin-city").html(document.getElementById("select_restaurant").options[document.getElementById("select_restaurant").selectedIndex].text)
        Cufon.replace(".sin-city");
        jQuery("div#firsttime").css("display","none");
        jQuery("#form_restaurant").css("display","block");
        //if(jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 8){
        if(jQuery.browser.msie){
          jQuery("ul.restaurant_menu").css("display","none");
          jQuery("ul#"+jQuery(this).attr("rel")).find("li:first-child div").hide().end().css("display","block").find("li:first-child div").slideDown();
        }
        else{
          jQuery("ul.restaurant_menu").slideUp("fast");//.css("display","none");
          jQuery("ul#"+jQuery(this).attr("rel")).slideDown();//css("display","block");
        }
        return false;
      });
    });
  }
  jQuery("select#select_restaurant").change(function(){
    var value = jQuery(this).val();
    if(value!='0') {
      jQuery.cookie("DamngoodCookie",null);
      jQuery.cookie("DamngoodCookie",value,{expires:365,path:"/"});
      jQuery("div#firsttime").css("display","none");
      jQuery(".sin-city").html(document.getElementById("select_restaurant").options[document.getElementById("select_restaurant").selectedIndex].text)
      Cufon.replace(".sin-city");
      //if(jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 8){
      if(jQuery.browser.msie){
        jQuery("ul.restaurant_menu").css("display","none");
        jQuery("ul#"+value).find("li:first-child div").hide().end().css("display","block").find("li:first-child div").slideDown();
      }
      else{
        jQuery("ul.restaurant_menu").slideUp("fast");//.css("display","none");
        jQuery("ul#"+value).slideDown();//css("display","block");
      }
    }
  });
  // END: Rasturant menu selector  
/*

  // START: Rasturant menu selector  
  jCookieValue=jQuery.cookie("DamngoodCookie");
  //console.log(jCookieValue)
  if( jCookieValue != null ) {
    jQuery("select#select_restaurant option[value='"+jCookieValue+"']").attr("selected","selected");
    jQuery("div#firsttime").css("display","none");
    jQuery("ul.restaurant_menu").css("display","none");
    //jQuery("ul#restaurant_info ul").css("display","none");
    jQuery("ul#restaurant_info > li").css("display","none");
    jQuery("ul#"+jCookieValue).css("display","block");
    var ind = jQuery("select#select_restaurant")[0].selectedIndex-1;
    //jQuery("ul#restaurant_info > li").eq(ind).find("ul").css("display","block");
    jQuery("ul#restaurant_info > li").eq(ind).css("display","block").parent().css("display","block");
  }
  else {
    jQuery("div#firsttime").css("display","block");
  }
  jQuery("select#select_restaurant").change(function(){
    var value = jQuery(this).val();
    if(value!='0') {
      jQuery.cookie("DamngoodCookie",null);
      jQuery.cookie("DamngoodCookie",value,{expires:90,path:"/"});
      jQuery("div#firsttime").css("display","none");
      jQuery("ul.restaurant_menu").css("display","none")//.slideUp(200);
      //jQuery("ul#restaurant_info ul").slideUp(200);
      jQuery("ul#restaurant_info > li").css("display","none")//.slideUp(200);//
      jQuery("ul#"+value).css("display","block")//.slideDown(400);
      var ind = jQuery(this)[0].selectedIndex-1;
      jQuery("ul#restaurant_info > li").eq(ind).css("display","block");//.slideDown(400);//
    }
  });
  // END: Rasturant menu selector  
*/  
  /* Åbningstider */
  //jQuery("#sidebar_left #restaurant_box #restaurant_info .item li:last-child h4").click(function() {
  jQuery("#sidebar_left #restaurant_box .restaurant_menu li.aabning h4").click(function() {
    jQuery(this).toggleClass('open');
    jQuery(this).next().slideToggle(75);
  });

  /* For links til at åbne i nyt vindue */
  $('#sidebar_left a[href^=http]').click( function() {
    window.open(this.href);
    return false;
  });

  // START: Frontpage banner
  jQuery('.frontpage #banner #banner_content').cycle({
    delay: 4500,
    speed: 500,
    prev: '#prev',
    next: '#next',
    pause: 1
  });
  // END: Frontpage banner
  
    // START: Gallery
  jQuery('.paragraph #gallery_content').cycle({ 
    delay: 4500, 
    speed: 500,
    prev: '#gallery_nav #prev', 
    next: '#gallery_nav #next',
    pause: 1
  });
  // END: Frontpage banner


  // START: Equal height for blocks in same rows
  // var currentTallest = 0,
  //   currentRowStart = 0,
  //   rowDivs = new Array(),
  //   $el,
  //   topPosition = 0;
  // jQuery('.col_2.box .paragraph, .col_3.box .paragraph').each(function() {
  //   $el = $(this);
  //   topPostion = $el.position().top;
  //   if (currentRowStart != topPostion) {
  //     // we just came to a new row.  Set all the heights on the completed row
  //     for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
  //       rowDivs[currentDiv].height(currentTallest);
  //     }
  //     // set the variables for the new row
  //     rowDivs.length = 0; // empty the array
  //     currentRowStart = topPostion;
  //     currentTallest = $el.height();
  //     rowDivs.push($el);
  //   }
  //   else {
  //     // another div on the current row.  Add it to the list and check if it's taller
  //     rowDivs.push($el);
  //     currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);
  //   }
  //   // do the last row
  //   for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
  //     rowDivs[currentDiv].height(currentTallest);
  //   }
  // });
  // END: Equal height for blocks in same rows

}); // Document ready



// START: Maps
function googleMap(map_Lat,map_Lng,shop_title) {
  var latlng = new google.maps.LatLng(map_Lat,map_Lng);
  var settings = {
    zoom: 15,
    center: latlng,
    mapTypeControl: true,
    mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
    navigationControl: true,
    navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
    mapTypeId: google.maps.MapTypeId.ROADMAP};
  var map = new google.maps.Map(document.getElementById("map_canvas"), settings);
  
  var infowindow = new google.maps.InfoWindow({
    content: googleMapContentString
  });
  
  var companyImage = new google.maps.MarkerImage('/files/Templates/Designs/bones/gfx/bones_map_icon.png',
    new google.maps.Size(68,93),
    new google.maps.Point(0,0),
    new google.maps.Point(34,93)
  );

  var companyShadow = new google.maps.MarkerImage('/files/Templates/Designs/bones/gfx/bones_map_shadow.png',
    new google.maps.Size(91,45),
    new google.maps.Point(0,0),
    new google.maps.Point(34,45));

  var companyPos = new google.maps.LatLng(map_Lat,map_Lng);

  var companyMarker = new google.maps.Marker({
    position: companyPos,
    map: map,
    icon: companyImage,
    shadow: companyShadow,
    title: shop_title,
    zIndex: 3});
  
  google.maps.event.addListener(companyMarker, 'click', function() {
    infowindow.open(map,companyMarker);
  });
}
jQuery(document).ready(function() {
  if(jQuery('#map_canvas').length!=0){
    googleMap(googleMapLat,googleMapLng,googleMapLinkTitle);
  }
});
// END: Maps




// START: Cufon
Cufon.replace('h1');
Cufon.replace('h2');
Cufon.replace('h3');

Cufon.replace('#sidebar_left #restaurant_box .restaurant_menu a', {
  textShadow: '0 1px 0 #fff'
});
Cufon.replace('#sidebar_left #restaurant_box h4', {
  textShadow: '0 1px 0 #fff'
});
Cufon.replace('#sidebar_left #restaurant_box #restaurant_info .item li h4', {
  textShadow: '0 1px 0 #fff'
});
Cufon.replace('#header #mainmenu ul li a', {
  textShadow: '0 1px 0 #000',
  hover: true
});
// END: Cufon







/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie = function(name, value, options) {
  if (typeof value != 'undefined') { // name and value given, set cookie
    options = options || {};
    if (value === null) {
      value = '';
      options.expires = -1;
    }
    var expires = '90';
    if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
      var date;
      if (typeof options.expires == 'number') {
        date = new Date();
        date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
      } else {
        date = options.expires;
      }
      expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
    }
    // CAUTION: Needed to parenthesize options.path and options.domain
    // in the following expressions, otherwise they evaluate to undefined
    // in the packed version for some reason...
    var path = options.path ? '; path=' + (options.path) : '';
    var domain = options.domain ? '; domain=' + (options.domain) : '';
    var secure = options.secure ? '; secure' : '';
    document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
  } else { // only name given, get cookie
    var cookieValue = null;
    if (document.cookie && document.cookie != '') {
      var cookies = document.cookie.split(';');
      for (var i = 0; i < cookies.length; i++) {
        var cookie = jQuery.trim(cookies[i]);
        // Does this cookie string begin with the name we want?
        if (cookie.substring(0, name.length + 1) == (name + '=')) {
          cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
          break;
        }
      }
    }
    return cookieValue;
  }
};
