
$(function(){
	
	var handPos = {	'but1' : '373px',	'but2' : '265px', 'but3' : '133px', 'but4' : '0' };
	if( $('#hand').hasClass('cartoons') )	var curHandPos = '373px';
	else if( $('#hand').hasClass('request') )	var curHandPos = '265px';
	else if( $('#hand').hasClass('illustrations') )	var curHandPos = '133px';
	else var curHandPos = '0px';
	
	$('#navigation a')
	.hover(function(){
			$('div#bgNav div[class="bgNav"] .topLine').css({top:'-8px'});
			$('#hand').stop();
			$('#hand').animate({left:handPos[$(this).attr('id')]}, 'fast');
			if( !$(this).hasClass('hovered') ) {
				$('.topLine').stop();
				$('#bg_'+$(this).attr('id')+' .topLine').animate({top:0}, 'fast');
			}
		},
		function(){
			$('div#bgNav .topLine').stop();
			$('div#bgNav div[class="bgNav"] .topLine').css({top:'-8px'});
			$('#hand').stop();
			$('#hand').animate({left:curHandPos}, 'fast' );
		});
	
	$('.aviaslider').aviaSlider({	
		blockSize: {height: 30, width:30},
		transition: 'fade', //fade
		display: 'all',
		betweenBlockDelay:10,
		backgroundOpacity:0.7,
		//slideControlls: 'none',
		autorotationSpeed:5
	});
	
	if( $('.slides_container').size() > 0 ) {
		$("#gallery").slides( {
			width: 720,
			height: 410,
			preload: false,
			preloadImage: '/images/slider/loading.gif',
			play: false,
			pause: 2500,
			slideSpeed:700,
			slideEasing: 'easeInOutBack',
			hoverPause: true
		 });
	}
	
	$('.slides_container div a').hover(
		function(){ $(this).find('img').eq(1).fadeOut(50); },
		function(){ $(this).find('img').eq(1).fadeIn(50); }	
	);
	
	$('.slides_container div span').hover(
		function(){ $(this).find('.adminLinkBlock').show(); },
		function(){ $(this).find('.adminLinkBlock').hide(); }	
	);
	
	setTimeout('setPaginationWidth()', 700)
	
	$('.lightbox').lightbox(); //{autoresize:false}

  $('.ui-button').hover(function(){ $(this).addClass('ui-state-hover'); }, function(){ $(this).removeClass('ui-state-hover'); });
	
});

function setPaginationWidth(){
	$('#gallery .pagination').fadeIn(400);
	$('#gallery .pagination').css({width:$('#gallery .pagination li').size()*20+'px'});
}

function getCurrentData() {
	var theDate = new Date();
	var curYear = (theDate.getYear() < 2000) ? theDate.getYear()+1900 : theDate.getYear();
	document.getElementById('month').value = (theDate.getMonth() + 1);
	document.getElementById('year').value = curYear;
	document.getElementById('date').value = theDate.getDate();
}

function parseQuery ( query ) {
   var Params = {};
   if ( ! query ) {return Params;}// return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}

function gup( name ){
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )   return "";
	else    return results[1];
}

function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};
parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};
