var paircount = 0;

/* If you want to desaturate after page loaded - use onload event
 * of image.
*/
function initImage(obj)
{
  obj.onload = null;
  var $newthis = $(obj);
  if ($.browser.msie)
  {
    // You need this only if desaturate png with aplha channel
    $newthis = $newthis.desaturateImgFix();
  }
  // class for easy switch between color/gray version
  $newthis.addClass("pair_" + ++paircount);
  var $cloned = $newthis.clone().attr('id', '');
  // reset onload event on cloned object
  $cloned.get(0).onload = null;
  // add cloned after original image, we will switch between
  // original and cloned later
  $cloned.insertAfter($newthis).addClass("color").hide();
  // desaturate original
  $newthis = $newthis.desaturate();
  // add events for switch between color/gray versions
  $newthis.bind("mouseenter mouseleave", desevent);
  $cloned.bind("mouseenter mouseleave", desevent);
};

function desevent(event)
{
  var classString = new String($(this).attr('class'));
  var pair = classString.match(/pair_\d+/);
  // first I try was $("."+pair).toggle() but IE switching very strange...
  $("."+pair).hide();
  if (event.type == 'mouseenter')
    $("."+pair).filter(".color").show();
  if (event.type == 'mouseleave')
    $("."+pair).filter(":not(.color)").show();
}

function simpleSlideShowStart(elem,waitTimer,fadeTimer)
{
	$(elem+' a').css({opacity: 0.0});
	$(elem+' a:first').css({opacity: 1.0}).addClass('show');
	setInterval("simpleSlideShowProcess('"+elem+"',"+fadeTimer+")",waitTimer);
}

function simpleSlideShowProcess(elem, fadeTimer)
{
    var current = ( $(elem+' a.show') ?  $(elem+' a.show') : $(elem+' a:first') );
    var next = ((current.next().length) ? current.next() : $(elem+' a:first'));
    next.css({opacity: 0}).addClass('show').animate({opacity: 1}, fadeTimer);
    current.animate({opacity: 0}, fadeTimer).removeClass('show');
}

function saturate(img) {
	var img2 = Pixastic.process(img, "desaturate");
	img2.onmouseover = function() {
		Pixastic.revert(this);
	}
}

$(document).ready(function(){
	// fancybox
	$("a.fancybox").fancybox();
	$("a.fancyframe").fancybox({
		'width'				: '90%',
		'height'			: '85%',
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});

	swfobject.embedSWF("/media/upload/logo.swf", "flashLogo", "398", "162", "9.0.0");
	swfobject.embedSWF("/media/upload/logo2_eng.swf", "flashLogo2", "398", "162", "9.0.0");

	$("a.inline").fancybox({
		'hideOnContentClick': true
	});

});
