var $j = jQuery.noConflict();

jQuery.toggleImages = function()
{
	var cssclass = arguments[0];

	$j('#headerwrapper').addClass(cssclass);
	$j('#header').addClass(cssclass);
	$j('#contentwrapper').addClass(cssclass);
	$j('#content').addClass(cssclass);
	$j('#header h1').addClass(cssclass);
	$j('#headermenu ul li.home').addClass('home_'+cssclass);
	$j('#headermenu ul li.portfolio').addClass('portfolio_'+cssclass);
	$j('#headermenu ul li.services').addClass('services_'+cssclass);
	$j('#headermenu ul li.about').addClass('about_'+cssclass);
	$j('#headermenu ul li.blog').addClass('blog_'+cssclass);
	$j('#headermenu ul li.contact').addClass('contact_'+cssclass);
	$j('#footerwrapper').addClass(cssclass);
	$j('#footer').addClass(cssclass);
	$j('#chillamenu ul li.facebook_chilla').addClass('facebook_chilla_'+cssclass);
	$j('#chillamenu ul li.twitter_chilla').addClass('twitter_chilla_'+cssclass);
}
jQuery.removeImagesClass = function()
{
	var cssclass = arguments[0];

	$j('#headerwrapper').removeClass(cssclass);
	$j('#header').removeClass(cssclass);
	$j('#contentwrapper').removeClass(cssclass);
	$j('#content').removeClass(cssclass);
	$j('#header h1').removeClass(cssclass);
	$j('#headermenu ul li.home').removeClass('home_'+cssclass);
	$j('#headermenu ul li.portfolio').removeClass('portfolio_'+cssclass);
	$j('#headermenu ul li.services').removeClass('services_'+cssclass);
	$j('#headermenu ul li.about').removeClass('about_'+cssclass);
	$j('#headermenu ul li.blog').removeClass('blog_'+cssclass);
	$j('#headermenu ul li.contact').removeClass('contact_'+cssclass);
	$j('#footerwrapper').removeClass(cssclass);
	$j('#footer').removeClass(cssclass);
	$j('#chillamenu ul li.facebook_chilla').removeClass('facebook_chilla_'+cssclass);
	$j('#chillamenu ul li.twitter_chilla').removeClass('twitter_chilla_'+cssclass);
}

$j(document).ready(function(){
	try {
		$j.preloadCssImages();
	} catch (e) {
		// do nothing
	}
	
	datetoday = new Date();
	timenow = datetoday.getTime();
	datetoday.setTime(timenow);
	thehour = datetoday.getHours();

	if (thehour >= 18 || thehour <= 6) {
		$j.toggleImages('night');
	} else {
		$j.toggleImages('day');
	}

	$j("a.sunmoon").mouseenter(function(){
	   if (thehour >= 18 || thehour <= 6) {
			$j.removeImagesClass('night');
	      	$j.toggleImages('day');
		} else {
			$j.removeImagesClass('day');
	      	$j.toggleImages('night');
		}
	});

	$j("a.sunmoon").mouseleave(function(){
	   	if (thehour >= 18 || thehour <= 6) {
			$j.removeImagesClass('day');
	      	$j.toggleImages('night');
		} else {
			$j.removeImagesClass('night');
	      	$j.toggleImages('day');
		}
	});

	$j("#portfolio_tabs").tabs( { fx: { opacity: 'toggle' }, load: function(event, ui) { 
		$j("a.group").fancybox({ 'hideOnContentClick': true }); 
		$j("a.group2").fancybox({ 'hideOnContentClick': true }); 
		app.initTooltips();
	} } );
	
	try {
		$j("#slider").easySlider({
			auto: true,
			continuous: true,
			numeric: true,
			pause: 6500
		});
	} catch (e) {
		// do nothing
	}
	
	app.initTooltips();
});

$j(function() { 
	$j("#portfolio_tabs").tabs( { fx: { opacity: 'toggle' } } );
 });

var app = {
	initTooltips: function() { 
		$j('a[href][title]').each(function() {
				try { $j(this).qtip("destroy"); } catch (e) { };
					$j(this).qtip({
					   content: {
					       text: false
					    },
					    position: {
					          corner: {
					             tooltip: 'topMiddle',
					             target: 'bottomMiddle'
					          }
					    },
					    style: {
					          border: {
					             width: 2,
					             radius: 6
					          },
					          padding: 6, 
					          textAlign: 'center',
					          tip: true,
					          name: 'cream' 
					       }
					});
		});
		$j('input.action').each(function() {
				try { $j(this).qtip("destroy"); } catch (e) { };
					$j(this).qtip({
					   content: {
					       text: false
					    },
					    position: {
					          corner: {
					             tooltip: 'topMiddle',
					             target: 'bottomMiddle'
					          }
					    },
					    style: {
					          border: {
					             width: 2,
					             radius: 6
					          },
					          padding: 6, 
					          textAlign: 'center',
					          tip: true,
					          name: 'cream' 
					       }
					});
		});
	}
}
