$(document).ready(function(){
	
	LazyLoad=function(){var f=document,g,b={},e={css:[],js:[]},a;function j(l,k){var m=f.createElement(l),d;for(d in k){if(k.hasOwnProperty(d)){m.setAttribute(d,k[d])}}return m}function h(d){var l=b[d];if(!l){return}var m=l.callback,k=l.urls;k.shift();if(!k.length){if(m){m.call(l.scope||window,l.obj)}b[d]=null;if(e[d].length){i(d)}}}function c(){if(a){return}var k=navigator.userAgent,l=parseFloat,d;a={gecko:0,ie:0,opera:0,webkit:0};d=k.match(/AppleWebKit\/(\S*)/);if(d&&d[1]){a.webkit=l(d[1])}else{d=k.match(/MSIE\s([^;]*)/);if(d&&d[1]){a.ie=l(d[1])}else{if((/Gecko\/(\S*)/).test(k)){a.gecko=1;d=k.match(/rv:([^\s\)]*)/);if(d&&d[1]){a.gecko=l(d[1])}}else{if(d=k.match(/Opera\/(\S*)/)){a.opera=l(d[1])}}}}}function i(r,q,s,m,t){var n,o,l,k,d;c();if(q){q=q.constructor===Array?q:[q];if(r==="css"||a.gecko||a.opera){e[r].push({urls:[].concat(q),callback:s,obj:m,scope:t})}else{for(n=0,o=q.length;n<o;++n){e[r].push({urls:[q[n]],callback:n===o-1?s:null,obj:m,scope:t})}}}if(b[r]||!(k=b[r]=e[r].shift())){return}g=g||f.getElementsByTagName("head")[0];q=k.urls;for(n=0,o=q.length;n<o;++n){d=q[n];if(r==="css"){l=j("link",{href:d,rel:"stylesheet",type:"text/css"})}else{l=j("script",{src:d})}if(a.ie){l.onreadystatechange=function(){var p=this.readyState;if(p==="loaded"||p==="complete"){this.onreadystatechange=null;h(r)}}}else{if(r==="css"&&(a.gecko||a.webkit)){setTimeout(function(){h(r)},50*o)}else{l.onload=l.onerror=function(){h(r)}}}g.appendChild(l)}}return{css:function(l,m,k,d){i("css",l,m,k,d)},js:function(l,m,k,d){i("js",l,m,k,d)}}}();

	var csbarl = $('div#sidebar ul li a').filter(function() {
		var currentURL = window.location.toString().split('/');
		var qstrck = currentURL[currentURL.length-1].indexOf('?');
		var cleanURL = false;
		if(qstrck > -1){
			cleanURL = currentURL[currentURL.length-1].substring(0, qstrck);
		}
		else{
			cleanURL = currentURL[currentURL.length-1];
		}
		if(cleanURL == '') return $(this).attr('href') == 'index.php';
		else{
			return $(this).attr('href') == cleanURL;
		}
	});
	
	csbarl.addClass('current');
	csbarl.wrapInner('<span></span>');
	var csbarlw = csbarl.contents().width()
	var nwcsbarlw = parseInt(csbarlw,10)+1;
	csbarl.css({'width':nwcsbarlw+'px'});

	$('.boxlink').click(function(){
		document.location.href = $(this).find('a').attr('href');
	});
	
	if($('div.img_cycle').length != 0){
		LazyLoad.js(['/includes/js/jquery.cycle.min.js'], function () {
			$('div.img_cycle').cycle({
				timeout:	2000,
				speed:		1000,
				sync:		1
			});
			
			$('div.img_cycle').cycle('pause');
			
			$('div.img_cycle').hover(
				function () {
					$(this).cycle('resume');
					$(this).cycle('next');
				},
				function () {
					$(this).cycle('pause');
				}
			);
			
		});
	}

	if($('a.enlarge').length != 0){
		LazyLoad.js(['/includes/js/fancyzoom.min.js'], function () {
			$('a.enlarge').fancyZoom({scaleImg: true, closeOnClick: false});
		});
	}
	
	if($('#sshow').length != 0){
		LazyLoad.js(['/includes/js/jquery.lightbox-0.5.min.js'], function () {
			$('head').append('<link rel="stylesheet" href="/includes/css/jquery.lightbox-0.5.css" type="text/css" media="screen, projection" />');
			$('#sshow a').lightBox({galleryName:$('#sshow').attr('title')});
		});
	}
	
	if($('#order').length != 0){
		LazyLoad.js(['/includes/js/jquery.maskedinput-1.2.2.min.js'], function (){return true;});
		LazyLoad.js(['/includes/js/order.js'], function (){return true;});
	}
	
	if($('#gtlform').length != 0){
		LazyLoad.js(['/includes/js/jquery.maskedinput-1.2.2.min.js'], function (){return true;});
		LazyLoad.js(['/includes/js/latest.js'], function (){return true;});
	}
	
	
	if($('#jplform').length != 0){
		LazyLoad.js(['/includes/js/jquery.maskedinput-1.2.2.min.js'], function (){return true;});
		LazyLoad.js(['/includes/js/presslist.js'], function (){return true;});
	}
	
	
	
	$('#sshow a.thumb img').each(function() {
		var maxWidth = 45;
		var maxHeight = 34;
		var maxRatio = maxWidth/maxHeight; // = 1.323529411764706
		var actWidth = $(this).width();
		var actHeight = $(this).height();
		var actRatio = actWidth/actHeight;
		if(actRatio > maxRatio){
			// make sure height is filled... then offset left
			var newWidth = parseInt((maxHeight/actHeight) * actWidth, 10);
			var leftPos = parseInt((newWidth-maxWidth)/2, 10);
			$(this).css({'width':newWidth,'height':maxHeight, 'left':'-'+leftPos+'px'});
		}
		else{
			// make sure width is filled... then offset top
			var newHeight = parseInt((maxWidth/actWidth) * actHeight, 10);
			var topPos = parseInt((newHeight-maxHeight)/2, 10);
			$(this).css({'width':maxWidth,'height':newHeight, 'top':'-'+topPos+'px'});
		}
	});

});

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1613320-6']);
_gaq.push(['_trackPageview']);
_gaq.push(['_trackPageLoadTime']);

(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

