		$.fn.slider = function(params,myObj)
		{
			myObj.scrollTo = $(this).attr("id");
			myObj.params = params;
			myObj.size = $(this).find("."+myObj.params).size();
			myObj.object=$(this);
			
			$(this).find(".next-page").click(function(){
				myScrollTo(myObj.scrollTo);
				myObj.active = $(myObj.object).find(".active");
				myObj.next = $(myObj.active).next();
				myObj.index = $("."+myObj.params).index(myObj.next);
				if (myObj.index!=-1)
				{
					$(myObj.active).removeClass("active");
					$(myObj.next).fadeIn(100);
					$(myObj.next).addClass("active");
				}

			});
			$(this).find(".previous-page").click(function(){
				myScrollTo(myObj.scrollTo);
				myObj.active = $(myObj.object).find(".active");
				myObj.prev = $(myObj.active).prev();
				myObj.index = $("."+myObj.params).index(myObj.prev);
				
				if (myObj.index!=-1)
				{
					$(myObj.active).removeClass("active");
					$(myObj.prev).fadeIn(500);
					$(myObj.prev).addClass("active");
					$(this).parents("."+myObj.params).children(".details").hide();
					$(this).parents("."+myObj.params).children(".details").slideDown("slow");
				}
			});
			$(this).find("."+myObj.params).children("h2").children("a").click(function()
				{
				myScrollTo(myObj.scrollTo);
				myObj.active = $(myObj.object).find(".active");
					myObj.index = $("."+myObj.params).index($(this).parents("."+myObj.params));
					$(myObj.active).removeClass("active");
					$(this).parents("."+myObj.params).addClass("active");
				});

			$(this).find(".page-navigation").children("ul").children("li").click(function()
			{
				myScrollTo(myObj.scrollTo);
				myObj.active = $(myObj.object).find(".active");
				myObj.index = $(myObj.object).find(".page-navigation").children("ul").children("li").index(this);
				$(myObj.active).removeClass("active");
				$(myObj.object).find("."+myObj.params).eq(myObj.index).addClass("active");
			});
		}

		$.fn.digest = function(myObj)
		{
			myObj.scrollTo = $(this).attr("id");
			myObj.size = $(this).find(".graphs").children("li").size();
			myObj.object=$(this).find(".graphs");
			myObj.mainObj = $(this);		
			$(this).find(".next-page").click(function(){
				myScrollTo(myObj.scrollTo);
				myObj.active = $(myObj.object).find(".active");
				myObj.next =  $(myObj.active).next().length ? $(myObj.active).next(): $(myObj.object).children("li:first-child");
				
				$(myObj.active).removeClass('active');
				$(myObj.next).css({opacity: 0.0})
				.addClass('active')
				.animate({opacity: 1.0}, 1000, function() {
				});
			});

			$(this).find(".previous-page").click(function(){
				myScrollTo(myObj.scrollTo);
				myObj.active = $(myObj.object).find(".active");
				myObj.prev =  $(myObj.active).prev().length ? $(myObj.active).prev(): $(myObj.object).children("li::last-child");
			
				$(myObj.active).removeClass('active');
				$(myObj.prev).css({opacity: 0.0})
				.addClass('active')
				.animate({opacity: 1.0}, 1000, function() {
				});
			});

			$(this).find(".page-navigation").children("ul").children("li").click(function()
			{
				myScrollTo(myObj.scrollTo);
				myObj.active = $(myObj.object).find(".active");
				myObj.index = $(myObj.mainObj).find(".page-navigation").children("ul").children("li").index(this);
				$(myObj.active).removeClass("active");
				$(myObj.object).children("li").eq(myObj.index).addClass("active");
			});
		}

		$.fn.closer = function(obj)
		{
			$(this).css({cursor: "pointer"});
			$(this).click(function()
			{
				caseOpenedGeo = "<a href=\"#\"><img src=\"images/panel-close-arrow.png\" alt=\"close\" width=\"22\" height=\"9\">დახურვა</a>";
				caseOpenedEng = "<a href=\"#\"><img src=\"images/panel-close-arrow.png\" alt=\"close\" width=\"22\" height=\"9\">CLOSE</a>";
				caseClosedGeo = "<a href=\"#\"><img src=\"images/panel-open-arrow.png\" alt=\"close\" width=\"22\" height=\"9\">გახსნა</a>";
				caseClosedEng = "<a href=\"#\"><img src=\"images/panel-open-arrow.png\" alt=\"close\" width=\"22\" height=\"9\">OPEN</a>";

				switch ($(this).html())
				{
				case caseOpenedGeo:
					$(this).html(caseClosedGeo);
					break;
				case caseClosedGeo:
					$(this).html(caseOpenedGeo);
					break;
				case caseOpenedEng:
					$(this).html(caseClosedEng);
					break;
				case caseClosedEng:
					$(this).html(caseOpenedEng);
					break;				
				}
				$(obj).toggle(400);
							return false;
			});

		};

		$.fn.gallery = function()
		{
			myGalleryObj = new Object();
			$(this).find(".gallery-binder").children("ul").children("li").children("a").click(function(){
				myGalleryObj.currentImage = $(this).attr("href");
				myGalleryObj.currentOriginalImage = myGalleryObj.currentImage.replace(/large/, "original");
				$(this).parents(".gallery-binder").children(".preview-block").children("a").attr("href",myGalleryObj.currentOriginalImage).children("img").attr("src",myGalleryObj.currentImage);
				return false;
			});
			$(".gallery-binder").children(".preview-block").children("a").click(function(){
			
			myWindow = window.open($(this).attr("href"),'gallery', 'toolbar=no,width=765,height=510,menubar=yes,resizable=yes,scrollbars=yes,status=yes,location=0');
					
					return false;
			});
		};

			
	
		function sitemap(langVers)
		{			
				data= "lang="+langVers;
					
				$.ajax({
					method: "get",
					url: "sitemap.php",
					data: data,
					dataType: "html",
					beforeSend: function(){  },
					complete: function(){  },
					success: function(html){
//						alert(html);
					}
				});
		};

		$.fn.indexes = function() {
			element = $(this);

			setInterval("indexfading(element)",3000);
		};

		function indexfading(element) {

			var active = $(element).find(".active");
			$.each (active,function(){
			var myNext =  $(this).next().length ? $(this).next(): $(this).parent("ul").children("li:first-child");

			$(this).removeClass('active');
			$(myNext).css({opacity: 0.0})
				$(myNext).addClass('active')
				$(myNext).animate({opacity: 1.0}, 1000, function() {
				});
			});
		}


	function myScrollTo(to)
	{
		var myScrollToVariable = $("#"+to).offset().top;
		$('html').animate({ scrollTop: myScrollToVariable }, 400);
	}

$.fn.center = function () {
    return this.each(function () {
        var t = jQuery(this);
        t.css({
            position:    'absolute', 
            left:        '50%', 
            zIndex:        '99'
        }).css({
            marginLeft:    '-' + (t.outerWidth() / 2) + 'px', 
            marginTop:    '-' + (t.outerHeight() / 2) + 'px'
        });

    });
};

$(document).ready(function(){
	myDepartments = new Object();
	myDigest = new Object();
	myTourism = new Object();

		$(".close-button").closer($(".add-info-tray > .column-binder")); 
		$("#departments").slider("department",myDepartments); 
		$("#tourism").slider("region",myTourism); 
		$("#tourism").gallery(); 
		$(".indexes").indexes(); 
		$(".digest").digest(myDigest);



$("object").hover(
	function(){
		graphOffsetTop = $(this).offset().top;
		graphOffsetLeft = $(this).offset().left;
		graphOffsetTop += $(this).height();

		var myxmlFileName = $(this).children("param:[name='xmlfilename']").attr("value");
		var myChartType = $(this).children("param:[name='movie']").attr("value");

		$("body").append($("<div>")
			.attr("id","largeView")
			.css({position: "absolute", top: graphOffsetTop, left: graphOffsetLeft, background: "white"})
			.html("<p>Click for large view</p>"));

		$("#largeView").click(function(){
			myWindow = window.open('graphdetailed.php?xmlfilename='+myxmlFileName+'&charttype='+myChartType,'myWindow', 'toolbar=no,width=830,height=630,menubar=yes,resizable=yes,scrollbars=yes,status=yes,location=0');
		});
	},
	function(){
		setTimeout ( "$(\"#largeView\").remove()", 700 );
	});

	$("#byDepartments, #byContacts, #newsByDepartnemts").change(function(){
		$(this).parents("form").submit();
	});

	$("#openGallery").click(function(){
		myWindow = window.open($(this).attr("href"),'gallery', 'toolbar=no,width=533,height=340,menubar=yes,resizable=yes,scrollbars=yes,status=yes,location=0');
		return false;
	});
});