(function(d){d.each(["backgroundColor","borderBottomColor","borderLeftColor","borderRightColor","borderTopColor","color","outlineColor"],function(f,e){d.fx.step[e]=function(g){if(g.state==0){g.start=c(g.elem,e);g.end=b(g.end)}g.elem.style[e]="rgb("+[Math.max(Math.min(parseInt((g.pos*(g.end[0]-g.start[0]))+g.start[0]),255),0),Math.max(Math.min(parseInt((g.pos*(g.end[1]-g.start[1]))+g.start[1]),255),0),Math.max(Math.min(parseInt((g.pos*(g.end[2]-g.start[2]))+g.start[2]),255),0)].join(",")+")"}});function b(f){var e;if(f&&f.constructor==Array&&f.length==3){return f}if(e=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(f)){return[parseInt(e[1]),parseInt(e[2]),parseInt(e[3])]}if(e=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(f)){return[parseFloat(e[1])*2.55,parseFloat(e[2])*2.55,parseFloat(e[3])*2.55]}if(e=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(f)){return[parseInt(e[1],16),parseInt(e[2],16),parseInt(e[3],16)]}if(e=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(f)){return[parseInt(e[1]+e[1],16),parseInt(e[2]+e[2],16),parseInt(e[3]+e[3],16)]}return a[d.trim(f).toLowerCase()]}function c(g,e){var f;do{f=d.curCSS(g,e);if(f!=""&&f!="transparent"||d.nodeName(g,"body")){break}e="backgroundColor"}while(g=g.parentNode);return b(f)}var a={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0]}})(jQuery);

jQuery.fn.center=function(absolute){return this.each(function(){var t=jQuery(this);t.css({position:absolute?'absolute':'fixed',left:'50%',top:'50%',zIndex:'99'}).css({marginLeft:'-'+(t.outerWidth()/2)+'px',marginTop:'-'+(t.outerHeight()/2)+'px'});if(absolute){t.css({marginTop:parseInt(t.css('marginTop'),10)+jQuery(window).scrollTop(),marginLeft:parseInt(t.css('marginLeft'),10)+jQuery(window).scrollLeft()})}})};

jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	}
});

jQuery.extend({
    slide: function($container, child_element_no, callback) {
        var $slider = $container.children(":first");
        var new_offset = $slider.children(':eq('+child_element_no+')').offset().left - $container.offset().left - ($slider.offset().left - $container.offset().left);
        $slider.animate( {left: -1 * new_offset}, 600, 'easeOutQuad', callback);
        return this;
    },
    slide_page: function($container, page_no, size, callback) {
        if (typeof(size) == 'undefined') {
            size = parseInt($container.parent().css('width').match(/\d+/));
        }
        var new_offset = size * page_no;
        $container.animate( {left: -1 * new_offset}, 600, 'easeOutQuad', callback);
        return this;
    },
    imgLoad: function(src, loaded_callback) {
        var img = new Image();
        $(img).load( function () {
            loaded_callback(img);
        });
        img.src = src;
        return this;
    },
    dimIn: function (user_css, callback, on_click) {
        $dim = $("#dim");
        if ($dim.length == 0) {
            $dim = $("<div />").attr('id', 'dim').css(
                {position: 'absolute',
                  top: 0,
                  left: 0,
                  width: '100%',
                  height: $(document).height(),
                  zIndex: 99999998,
                  background: '#333',
                  opacity: .4});
            $('body').prepend($dim);
        }
        if (on_click != undefined) {
            $dim.click(on_click);
        }
        if ($dim.data('act') == true) return false;
        if (user_css != undefined) {
            $dim.css(user_css);
        }
        return $dim.data('act', true).fadeIn(400, callback);
    },
    dimOut: function (callback) {
        $dim = $("#dim").unbind('click');
        if ($dim.data('act') == true) {
            $dim.fadeOut(400, callback).data('act', false);
        }
    }
});

jQuery.fn.extend({
	fadeOver: function (speed, callback) {
		c = this.clone();
		c.css( { position: 'absolute',
				 width: this.width(),
				 height: this.height(),
				 display: 'none',
				 zIndex: 2 } );
		this.parent().css( { width: this.parent().width(),
							 height: this.parent().height() } );
		c.insertBefore(this);
		c.fadeIn(speed, function () {
			c.next().remove();
			c.css( { position: 'relative', zIndex: 1 } );
			if (typeof(callback) == 'function') callback();
		});
		return this;
	}
});

var is_ie6 = /MSIE 6/i.test(navigator.userAgent);

var primer = {
	
	required: function () {
	
		
	},
	
	index: function () {
		
		$("#menu > li").hover( function () {
			
			$(this).find(".foto").addClass("act");
			
		}, function () {
			
			$(this).find(".foto").removeClass("act");
			
		});
		
	},
		
	vote: function () {
		
		
	},
	
	gallery_prod: function () {
		
		$("#thumbs a").click( function () {
			
			if ($(this).hasClass('act')) return false;
			
			$(this).parent().children('.act').removeClass('act');
			$(this).addClass('act');
			
			$.imgLoad($(this).attr('href'), function (img) {
				$("#preview").fadeOver(400);
				$("#preview").attr('src', img.src);
			});
			
			return false;
			
		});
		
	},
	
	gallery: function () {
		
		var current_photo = null;
		var loadedImages = new Array();
		var photo_count = $("#gallery a").length;
		
		$("#gallery a").click( function () {
			
			$("#dark").width($(document).width()).height($(document).height()).css( { opacity: 0.4 } ).fadeIn('fast');
			
			var y;
			if (self.pageYOffset)  {
				y = self.pageYOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {
				y = document.documentElement.scrollTop;
			} else if (document.body) {
				y = document.body.scrollTop;
			}

			$("#popup_photo").css('top', (y + 50)).fadeIn();
			
			showPhotoInPopup($(this));
			
			return false;
											  
		});
		
		function showPhotoInPopup($img_current) {
			
			$("#title_photo").html($img_current.attr("title"));
			current_photo = $("#gallery a").index($img_current);

			var photo_url = $img_current.css('background-image');
			
			photo_url.match(/i.php\?f=(.*?)\&w=/);
			photo_url = RegExp.$1;
			
			if ($.inArray('i.php?f=' + photo_url + '&w=600&h=450&m=8&r=00&g=00&b=00', loadedImages) != -1) {
				
				$("#img_preview").fadeOut('fast', function () {
															
					$("#img_preview").attr( { 'src': 'i.php?f=' + photo_url + '&w=600&h=450&m=8&r=00&g=00&b=00', 'alt': $img_current.attr('alt') } ).fadeIn('fast');

				});
				
			} else {
			
				var img = new Image();
				
				$("#img_preview").fadeOut('normal', function () {

					$("#loading").fadeIn('fast');
					
					$(img).load( function () {
									   
						loadedImages.push('i.php?f=' + photo_url + '&w=600&h=450&m=8&r=00&g=00&b=00');
										   
						$("#loading").stop().fadeOut('fast');
										   
						$("#img_preview").attr( { 'src': img.src, 'alt': $img_current.attr('alt') } ).fadeIn('fast');
	
					});
					
					img.src = '/i.php?f=' + photo_url + '&w=600&h=450&m=8&r=00&g=00&b=00';

				});
															  
			}
			
			if (photo_count == (current_photo + 1)) {
			
				$('#popup_photo .next').hide();
				
			} else {
				
				$('#popup_photo .next').show();
				
			}
			
			if (0 == current_photo) {
			
				$('#popup_photo .prev').hide();
				
			} else {
				
				$('#popup_photo .prev').show();
				
			}
			
		}
		
		$("#btn_close_popup").click( function () { 
			$("#img_preview").hide(); 
			$("#popup_photo").fadeOut("fast"); 
			$("#dark").fadeOut(); 
		} );
		
		$('#popup_photo .next').click( function () {
												 
			showPhotoInPopup($("#gallery a:eq(" + (++current_photo) + ")"));
												 
		});

		$('#popup_photo .prev').click( function () {
												 
			showPhotoInPopup($("#gallery a:eq(" + (--current_photo) + ")"));			
												 
		});
		
		$("#dark").click( function () {
			
			$("#btn_close_popup").click();
			
		});
		
	}
	
}
	
$(function () {

	var module = $("body:first").attr("class").match(/(mod-)([a-zA-Z]+)/)[2];

	primer.required();
	
	if (module == 'index') {
		primer.index();
	}

    if ($(".page-thumbs").length > 0) {

        $(".page-thumbs a").click( function () {
            popup($(this).attr('href'));
            return false;
        });

    }
	
});

function printpage() {
	var url = document.location.href;
	
	for (i = url.length; i > 0; i--) {
		if (url.charAt(i) == '?') {
			url = url + '&';
			break;
		} else if ((url.charAt(i) == '/') || (url.charAt(i) == '\\')) {
			url = url + '?';
			break;
		}
	}

	win = window.open(url + 'do=print', 'popup', 'toolbar = 0, scrollbars = 1, status = 0');
	win.window.print();
}

//- required
function popup(url) {

    if (typeof(window.popuped) == 'undefined') {
        window.popuped = $('<div style="z-index:9999999999; display: none; cursor: pointer; position: absolute; padding: 7px; background: #ffffff; box-shadow: 0 0 5px #666; -moz-box-shadow: 0 0 5px #666; -webkit-box-shadow: 0 0 5px #666;" />').appendTo('body').click( function () {
            $(this).find('img').fadeOut(400).end().fadeOut(400);$.dimOut();
        } );
        $('<img style="display: none" />').appendTo(window.popuped);
    }

    $popuped = window.popuped;

    $.dimIn({}, null, function () {
        window.popuped.click();
    });

    var props = {width: 100,
                  height: 100,
                  left: Math.ceil($(window).width() / 2) - 50,
                  top: $(document).scrollTop() + Math.ceil(($(window).height() - 25) / 2) - 20};

    if ($popuped.css('display') == 'none') {
        $popuped.css(props);
    } else {
        $popuped.find('img').fadeOut(400);
    }

    var img = new Image();

    $popuped.fadeIn(400);

    $(img).load( function () {

        $popuped.find('img').attr('src', img.src).end().animate(
            {
                left: Math.ceil(($(window).width() - img.width) / 2),
                top: (($(window).height() - img.height) / 2) + $(document).scrollTop(),
                height: img.height,
                width: img.width
            }, 400, function () {
                $(this).find('img').fadeIn('fast');
            }
        );


    });

    img.src = url;

}
