(function($){
	$.fn.expandCorners = function(options) {
		var opts = $.extend({}, $.fn.expandCorners.defaults, options);
		this.each(function() {
			$(this).css({position:"relative", overflow:"hidden"});
			
			if (options) {
				if (options.z == 616) {
					$(this).wrapInner('<div class="corntent i22"></div>')
						   .prepend('<div class="corners"><div class="c i11"></div><div class="c i13"></div><div class="h i12"></div><div class="v i21"></div><div class="v i23"></div></div>');
				} else {
					var corners = $(document.createElement("div")).attr("class","corners");
					$.each(opts.cs, function(cl, bk) {
						var c = $(document.createElement("div")).attr("class", "c "+ cl);
						corners.append(c);
					});

					$(this).wrapInner('<div class="corntent i22"></div>')
						   .prepend(corners);

					$.each(opts.cs, function(cl, bk) {
						var ci = corners.children(".c." + cl);
						var cstr = ci.css("background-image").replace("/c7/", bk);
						ci.css("background-image",cstr);
						ci.css("z-index",opts.z);
					});
				}
			} else {
				$(this).wrapInner('<div class="corntent i22"></div>')
					   .prepend('<div class="corners"><div class="c i11"></div><div class="c i13"></div><div class="c i31"></div><div class="c i33"></div><div class="h i12"></div><div class="h i32"></div><div class="v i21"></div><div class="v i23"></div></div>');
			}
		});
	}
	$.fn.expandCorners.defaults = {cs:{i11:"/cc/", i31:"/cc/", i31:"/cc/", i33:"/cc/"}, z:10}
})(jQuery);

(function($){
	$.fn.footstanding = function() {
		var tosub = parseInt($(".gl.loco").height()) + parseInt($(".gl.head").height()) + parseInt($(".gl.foot").height()) - 1;
		
		$(this).height("auto");
		
		if($(window).height() - tosub > $(this).height())
			$(this).height($(window).height() - tosub);
		else
			$(this).height("auto");
	}
})(jQuery);

(function($){
	$.fn.autoscroll = function(s) {
		$('html,body').animate(
			{scrollTop: $(this).offset().top}, s
		);
	}
})(jQuery);

(function($){
	$.fn.delegator = function(href) {
		$(this).load('tpl/' + lang + '/' + href + '.htm',function(){
		    $(".corn1").not(".corn1:has(.corners)").expandCorners();
			
			$(".dfold.last .dfoot").expandCorners({cs:{i31:"/ccend/", i33:"/ccend/"}, z:20});
			$(".dfold:not(.first) .dhead").expandCorners({cs:{i31:"/ccff/", i33:"/ccff/"}, z:20});
			$(".dfold .dhead").expandCorners({cs:{i11:"/cc/", i13:"/cc/"}, z:20});
			$(".dfold:not(.last) .dfoot").expandCorners({cs:{i31:"/cc/", i33:"/cc/"}, z:20});
			
/**/		$(".corners").pngFix();

// setting dfold heights

			$(".list li, .dfold").each(function() {
				$(this).append('<div class="clear"></div>');
			});

			$(".df.row").each(function() {
				$(this).append('<div class="clear"></div>');
				var maxH = 0;
				$(this).children(".dcont").each(function() {
					if ($(this).height() > maxH) maxH = $(this).height();
				});
				$(this).children(".dcont").each(function() {
					$(this).height(maxH);
				});
			});

			$(".hrow").each(function() {
				var maxH = 0;
				$(this).children(".dfold").children(".dcont").each(function() {
					if ($(this).height() > maxH) maxH = $(this).height();
				});
				$(this).children(".dfold").children(".dcont").each(function() {
					$(this).height(maxH);
				});
			});
			
			$(".middle").each(function() {
				var phalfH = $(this).parent().height()/2;
				var chalfH = $(this).height()/2;
				$(this).css({position:"relative", top: phalfH-chalfH });
			});
			
			$(".center").each(function() {
				var phalfW = $(this).parent().width()/2;
				var chalfW = $(this).width()/2;
				$(this).css({position:"relative", left: phalfW-chalfW });
			});
			
			$(".reset").click(function() {
				$(".loco").autoscroll(350);
			});
			
			$(".gl.body").footstanding();
			
		});
	}
})(jQuery);

function getMovie(movieName) {
	if (window.document[movieName])
		return window.document[movieName];

	if (navigator.appName.indexOf("Microsoft Internet")==-1)
		if (document.embeds && document.embeds[movieName])
			return document.embeds[movieName];

	if (navigator.appName.indexOf("Microsoft Internet")!=-1)
		return document.getElementById(movieName);
}

function goFlash(href) {
	getMovie("gl_menu").jsClick(href);
}

function goFlashTranslate(labels) {
	getMovie("gl_menu").jsTranslate(labels);
}


