function toggleCats(master, className) {
  var cats = document.getElementsByClassName(className);
  if (master.checked) {
    for (i = 0; i < cats.length; i++) { cats[i].checked = true; }
  } else {
    for (i = 0; i < cats.length; i++) { cats[i].checked = false; }
  }
}
function toggleMaster(checkbox, master) {
  master = $(master)
  if(!master) return
  if (master.checked && !checkbox.checked) {
    master.checked = false;
  }
}

// if($('busy')){
// 	Ajax.Responders.register({
// 	  onCreate: function() {
// 	    if(Ajax.activeRequestCount>0)
// 	      Effect.Appear('busy',{duration:0.5,queue:'end'});
// 	  },
// 	  onComplete: function() {
// 	    if(Ajax.activeRequestCount==0)
// 	      Effect.Fade('busy',{duration:0.5,queue:'end'});
// 	  }
// 	});
// }

jQuery(document).ready(function() {

	// initialize iFishEye on home page
	if(typeof iFishEye == 'function') {
		new iFishEye({
			container: $("iFishEye_example_1"),
			norm: "L2"
		});
	}

	// initialize iCarousel on home page
	if(typeof iCarousel == 'function') {
		new iCarousel("carousel_content", {
			item: {
				klass: "places",
				size: 58
			},
		  animation: {
		    type: "scroll",
				direction: "top",
		    rotate: {
		      type: "auto",
					amount: 3
				}
		  }
		});
	}

 	// v1.0 | www.TJKDesign.com
  var e = document.getElementById('wraper');
  if (e){
    var a=e.getElementsByTagName('a');
    for (var i=0;i<a.length;i++){
    if (a[i].getAttribute('href') != null && a[i].getAttribute('href').indexOf("://") >= 0 && a[i].getAttribute('href').toUpperCase().indexOf(document.domain.toUpperCase()) == -1){
        a[i].className+=a[i].className?' outlink':'outlink';
        a[i].title+=' (opens in new window)';
        a[i].onclick=function(){newWin=window.open(this.href,'popup','height=600,width=800,scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,location=yes,status=yes');if(window.focus){newWin.focus()} return false;}
//      a[i].onkeypress=function(){newWin=window.open(this.href,'popup');if(window.focus){newWin.focus()} return false;}
      }
    }
  }

	if(typeof supersleight == 'function') {
		supersleight.init;
	}

	if(jQuery.facebox) {
	  jQuery('a[rel*=facebox]').facebox();
	}

	jQuery('a[rel*=popup]').click(function() {
	  window.open(jQuery(this).attr('href'),'TAF','height=700,width=480,scrollbars=yes,resizable=yes');
	  return false;
	});
	
	jQuery.ajaxSetup({ 'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")} })
	
	if(jQuery.ajaxForm) {
		jQuery('form.rjs').ajaxForm(function() { alert('Atta boy!') })
	}

	// // helper functions for Ajaxifying standard links and forms, and evaluating returned Javascript
	//   $("a.rjs").click( function() {
	//     $.ajax({
	//         url: this.href,
	//         dataType: "script",
	//         beforeSend: function(xhr) {xhr.setRequestHeader("Accept", "text/javascript");}
	//     });
	//     return false;
	//   });
	//   // requires jQuery.form plugin
	//   $("form.rjs").ajaxForm({
	//     dataType: 'script',
	//     beforeSend: function(xhr) {xhr.setRequestHeader("Accept", "text/javascript");},
	//     resetForm: true
	//   });

	/*
	CSS Browser Selector v0.2.7
	Rafael Lima (http://rafael.adm.br)
	http://rafael.adm.br/css_browser_selector
	License: http://creativecommons.org/licenses/by/2.5/
	Contributors: http://rafael.adm.br/css_browser_selector#contributors
	*/
	var ua=navigator.userAgent.toLowerCase(),is=function(t){return ua.indexOf(t) != -1;},h=document.getElementsByTagName('html')[0],b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?'gecko ff2':is('firefox/3')?'gecko ff3':is('gecko/')?'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';var c=b+os+' js'; h.className += h.className?' '+c:c;

	if(jQuery.countdown) {
		var drawing = new Date();
		var modifier = new Array(4, 3, 2, 1, 0, 6, 5); // number of days until drawing day
		drawing.setDate(drawing.getDate() + modifier[drawing.getDay()]);
		drawing.setHours(17);
		drawing.setMinutes(0);
		drawing.setSeconds(0);
		jQuery('#countdown').countdown({until: drawing, format: 'dHM', layout: '%D%n %l%D %H%n %l%H and %M%nn %l%M', description: ''});
	}
});
