//-------------------------------------------------------------------------------------------------------
// ClearTypeFadeTo / ClearTypeFadeIn / ClearTypeFadeOut
//
// Custom fade in and fade out functions for jQuery that will work around
// IE's bug with bold text in elements that have opacity filters set when
// also using Window's ClearType text rendering.
//
// New Parameter:
// bgColor    The color to set the background if none specified in the CSS (default is '#fff')
//
// Examples:
// $('div').ClearTypeFadeIn({ speed: 1500 });
// $('div').ClearTypeFadeIn({ speed: 1500, bgColor: '#ff6666', callback: myCallback });
// $('div').ClearTypeFadeOut({ speed: 1500, callback: function() { alert('Fade Out complete') } });
//
// Notes on the interaction of ClearType with DXTransforms in IE7
// http://blogs.msdn.com/ie/archive/2006/08/31/730887.aspx
(function($) {

	$.fn.ClearTypeFadeTo = function(options) {
		if (options)
			$(this)
				.show()
				.each(function() {
					if (jQuery.browser.msie) {
						// Save the original background color
						$(this).attr('oBgColor', $(this).css('background-color'));
						// Set the bgColor so that bold text renders correctly (bug with IE/ClearType/bold text)
						$(this).css({ 'background-color': (options.bgColor ? options.bgColor : '#fff') })
					}
				})
				.fadeTo(options.speed, options.opacity, function() {
					if (jQuery.browser.msie) {
						// ClearType can only be turned back on if this is a full fade in or
						// fade out. Partial opacity will still have the problem because the
						// filter style must remain. So, in the latter case, we will leave the
						// background color and 'filter' style in place.
						if (options.opacity == 0 || options.opacity == 1) {
							// Reset the background color if we saved it previously
							$(this).css({ 'background-color': $(this).attr('oBgColor') }).removeAttr('oBgColor');
							// Remove the 'filter' style to restore ClearType functionality.
							$(this).get(0).style.removeAttribute('filter');
						}
					}
					if (options.callback != undefined) options.callback();
				});
	};

	$.fn.ClearTypeFadeIn = function(options) {
		if (options)
			$(this)
				.css({ opacity: 0 })
				.ClearTypeFadeTo({ speed: options.speed, opacity: 1, callback: options.callback });
	};

	$.fn.ClearTypeFadeOut = function(options) {
		if (options)
			$(this)
				.css({ opacity: 1 })
				.ClearTypeFadeTo({ speed: options.speed, opacity: 0, callback: options.callback });
	};
})(jQuery);


(function($) {
		  
	$.fn.swapImg = function(src) {
        var $img = this;
        var actions = 2;
        var img = $('<img src="' + src + '" />').load(next);
        $img.fadeOut("fast", next);
       
        function next() {
            if( --actions ) return;
			$img.hide();
            $img.attr({ src: src });
			$img.fadeIn("fast");
        }
    }; 
})(jQuery);	

if (!window.console || !console.firebug) {  
	var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",  
	"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];  

	window.console = {};  
	
	for (var i = 0; i < names.length; ++i)  
		window.console[names[i]] = function() {}  
}  

function initGallery() {
	// gallery
	$(".thumbs img").css('opacity', 0.6);
	$(".thumbs img.active").css('opacity', 1);
	
	$(".thumbs img").mouseover(function() {
		$(this).css('opacity', 1);	
	});
	
	$(".thumbs img").mouseout(function() {
		$(this).css('opacity', 0.6);	
		$(".thumbs img.active").css('opacity', 1);
	});
	
	$("div.gallery div.img-wrap").hide();
	$("div.gallery div.img-wrap-active").show();
	  
	// click small thumb
	$(".thumbs img").click(function() {
		$(".thumbs img").css('opacity', 0.6);
		$(".thumbs img").removeClass('active');
		$(this).css('opacity', 1)
		$(this).addClass('active');
		
		var string = $(this).attr('id');
		var part = string.split('-');
		var id = part[1];
		
		$("div.gallery div.img-wrap-active").ClearTypeFadeOut({ speed: 400, callback: function() {
			$("div.gallery div.img-wrap-active").css('display', 'none');
			$("div.gallery div.img-wrap-active").removeClass('img-wrap-active');
			
			$("#img-wrap_" + id).addClass('img-wrap-active');			
			$("#img-wrap_" + id).css('display', 'block');
			$("#img-wrap_" + id).css('opacity', 0);
			
			window.setTimeout(function(){
				$("#img-wrap_" + id).ClearTypeFadeIn({ speed: 500 });						   
			}, 100);

		} });		
	});		
}


$(function() {
	
	if ($(".slideshow ul li").length > 4)
	{
		$(".slideshow").jCarouselLite({
			btnNext: ".next",
			btnPrev: ".prev",
			visible: 4,
			//easing: "bounceout",
			//speed: 1000,
			circular: false
	
		});
	}
	
	
	
	// slideshow
	$(".slideshow ul li img").css('opacity', 0.6);
	$(".slideshow ul li img.active").css('opacity', 1);
	
	$(".slideshow ul li img").mouseover(function() {
		$(this).css('opacity', 1);	
	});
	
	$(".slideshow ul li img").mouseout(function() {
		$(this).css('opacity', 0.6);	
		$(".slideshow ul li img.active").css('opacity', 1);
	});
	
	$(".slideshow ul li img").click(function() {
		$(".slideshow ul li img").css('opacity', 0.6);
		$(".slideshow img").removeClass('active');
		
		var string = $(this).attr('id');
		var part = string.split('-');
		var gallery_id = part[1];
		
		$("div.gallery").css("opacity", "1");
		$("div.gallery").ClearTypeFadeOut({ speed: 250, callback: function() { 	
			$("div.gallery").css("opacity", "0");
			
			$.ajax({
					type: "GET",
					url: "gallery.php?d="+Math.random() * 100000,
					dataType: "html",
					global: 'false',
					data: "gallery_id=" + gallery_id + "&load=1",				
					success: function(html){		
						$("div.gallery-wrap").html(html);	
						window.setTimeout(function(){
							$("div.gallery").ClearTypeFadeIn({ speed: 500 });								   
						}, 0);
						
			}});							  
												  
		}});

		$(this).css('opacity', 1)
		$(this).addClass('active');
	});	
	
	initGallery();

});
