﻿// CO: http://www.quirksmode.org/js/cookies.html

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


document.documentElement.className += ' js';
jQuery.ajaxSettings.traditional = true;


$(function() {
  $('.imagemenu a').append('<div class="mask"></div>');
  $('.thumbstrip .thumbs a').append('<div class="mask"></div>');
});


$(function() {
  $('.menu li.active > ul').each(function() {
    $(this).slideDown('slow').parent('li').data('isOpen', true);
  });
});


$(function() {
  $('.menu a').click(function() {
    var menuspeed = 'slow';
    var href = this.href;

    var $parent_li = $(this).parent('.menu li');
    var $show_li = $(this).parents('.menu li');

    if ($parent_li.data('isOpen')==true) {
      $show_li = $show_li.not($parent_li);
    }

    var $hide_ul = $('.menu li').not($show_li).data('isOpen', false).children('ul:visible');

    $hide_ul.slideUp(menuspeed, function () {
      if(href) {
        window.location.href=href;
      }
    });

    $show_li.data('isOpen', true).children('ul').slideDown(menuspeed);

    return $hide_ul.length==0?true:false;
  });
});

var setupDnD = function(tableId, postVar, postUrl) {
  var prefix = tableId + '-' + postVar + '-';
  $('#' + tableId).tableDnD({
    dragHandle: 'tDnD_dragHandle',
    onDrop: function(table, row) {
      var $rows = $(table).find('tbody tr[id^=' + prefix + ']');
      var postData = {};
      postData[postVar] = $.map($rows, function(o, i) { return o.id.substring(prefix.length); });
      $.post(postUrl, postData);
    }
  });
}

