// Init tc_slide_show
// Pre-DOM: Load Global resource files/libraries that are NOT dependent on the DOM being ready
// Load js
init.preload.js('lib/zeroclipboard.js');
init.preload.js('app/slideshow.js');
init.preload.js('lib/jquery/plugin/jquery.carousel.js');
init.preload.js('lib/jquery/plugin/jquery.validate.js');

// Load css
init.preload.css('dark.css');
init.preload.css('slideshow.css');

if (browser.msie7) {
  init.preload.css('ie7.css');
} else if (browser.msie6) {
  init.preload.css('ie6.css');
  init.preload.js('lib/supersleight.js'); // IE 6 only
}

// Post-DOM: Load all js files/libraries that ARE dependent on the DOM being ready
function moduleReady(){ // include items here that are not Global

}

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 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+";";
}

function eraseCookie(name) {
  document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT;" + ";";
}

var preURL = readCookie('preURL');
var sExitURL = document.referrer;
var currentURL=document.URL;
var pos=currentURL.indexOf("slidevalue");
if(pos == -1 && (sExitURL != null && sExitURL != '')){
  createCookie('exiturl',sExitURL,1);
}

function exitSlideShow() {
  sExitURL = readCookie('exiturl');
  if(sExitURL == null || sExitURL == '') {
    if(preURL != null && preURL != '') {
      sExitURL=preURL;
	} else {
	  sExitURL="http://www.travelchannel.com/";
	}
  }
  window.location = sExitURL;
  if(sExitURL != null && sExitURL != '') eraseCookie('exiturl');
  if(preURL != null && preURL != '') eraseCookie('preURL');
}
