if (typeof menu_type == 'undefined') menu_type = '';
$(document).ready(function(){
	if (page_name == 'summer') {
		var movie_name = 'pano4.swf';
	}
	else {
		var movie_num = Math.ceil(Math.random() * 5);
		if (movie_num == 4) movie_num = 3;
		var movie_name = 'pano' + movie_num + '.swf?ishomepage=' + (page_name == 'home' ? 'yes' : 'no');
	}
	//var movie_name = 'pano1.swf?ishomepage=no';
	var FO = { movie:movie_name, width:"895px", height:"287px",	majorversion:"8", build:"0", scale: 'noscale', wmode: 'transparent',  swliveconnect:"true"};
	var FO_video = { movie:'video_small.swf', width:"162px", height:"122px",	majorversion:"8", build:"0", scale: 'noscale', wmode: 'transparent',  swliveconnect:"true"};
	if (UFO.hasFlashVersion(Number(FO.majorversion) + Number(FO.build / 10))) {
		UFO.create(FO, "pano");
		UFO.create(FO_video, "video-bg");
	} else {
		$('#noflash').show().css('backgroundImage', 'url(images/hed.jpg)');
	}

	if ($.browser.mozilla) {
		flash_intId = setInterval(iframeSwitch, 100);
	} else {
		$('#pano').show();
	}


	$('a').click(function(){
		this.blur();
	});
	/*var preload = [];
	var preload_images = [];*/
	MainMenu.init();
	$('#menu .item_maps, .link-map').click(function(){
		var wid = self.screen.width - 24;
		if (wid > 2000) wid = 2000;
		var hei = wid * (1400 / 2000);
		var x = (self.screen.width - wid) / 2;
		var y = (self.screen.height - hei) / 2;
		window.open('map.html','', 'top='+y+', left='+x+', screenX='+x+', screenY='+y+', width='+wid+', height='+hei+', menubar=no, status=no, scrollbars=no, resizable=no, toolbar=no');
		return false;
	});
	Scrapbook.init();
	Banners.init();
	$('#video').click(function(){
		window.open('popup_video.html','', 'top=150, left=250, screenX=250, screenY=150, width=320, height=320, menubar=no, status=no, scrollbars=no, resizable=no, toolbar=no');
	});
	$('#banner3')
	.click(function(){
		Scrapbook.showCurrent();
	});

	$('#banner3,  #banner4, #banner1, #banner2 ').hover(
		function() {
			$(this).find('.label-text-normal').hide();
			$(this).find('.label-text-active').show();
		},
		function() {
			$(this).find('.label-text-active').hide();
			$(this).find('.label-text-normal').show();
		}
	);

	$('#travel-now').hover(
		function(){
			$(this).children().css('backgroundImage', 'url(images/travel_1.png)');
		},
		function(){
			$(this).children().css('backgroundImage', 'url(images/travel_2.png)');
		}
	);
	image_preload('images/travel_1.png');

	if (page_name == 'home') {
		Popunder_gza.init();
		image_preload('images/home/more_axalli2.gif');
		$('#showmore').hover(
			function(){
				$(this).css('backgroundImage', 'url(images/home/more_axalli2.gif)');
			},
			function() {
				$(this).css('backgroundImage', 'url(images/home/more_axali.gif)');
			}
		);


		$('#gza-tbilisi').click(function(){
			Popunder_gza.cur_image = 0;
			Popunder_gza.showCurrent();
		});
		$('#gza-mtskheta').click(function(){
			Popunder_gza.cur_image = 2;
			Popunder_gza.showCurrent();
		});
		$('#gza-ananuri').click(function(){
			Popunder_gza.cur_image = 1;
			Popunder_gza.showCurrent();
		});
		$('#gza-gudauri').click(function(){
			Popunder_gza.cur_image = 3;
			Popunder_gza.showCurrent();
		});

		//Popunder_gza.showCurrent();
		$('#showmore').click(
		function(){
			$(this).hide();
			$('#text-short').hide();
			$('#text-long').show();
		});


		$('#amindi-top div').each(function(){
			image_preload($(this).attr('img_hover'));
		});
		$('#amindi .hover')
			.hover(
				function(){
					$('#amindi-top').css('backgroundImage', 'url(images/home/amindi/' + $(this).attr('day_id') + '.jpg)');
					$('#amindi-content div.day-content').hide();
					$('#amindi-day-' + $(this).attr('day_id')).show();



					var title = $('#day_title_' + $(this).attr('day_id'));
					title.attr('img_normal', title.css('backgroundImage'));
					title.css('backgroundImage', 'url(' + title.attr('img_hover') + ')');
					//alert('url(' + title.attr('img_hover') + ')');


					$('#amindi-top div').not(this).each(function(){
						$(this).css('backgroundImage', $(this).attr('img_normal'));
					});
				},
				function(){
				}
			)
			.each(
				function() {
					//preload.push('images/home/amindi/' + $(this).attr('day_id') + '.jpg');
					image_preload('images/home/amindi/' + $(this).attr('day_id') + '.jpg');
				}
			);
	}
	if (page_name == 'hotels') {
		Popunder.init();

		$('.barati .barati-label')
		.each(function(){
			image_preload($(this).attr('hover_img'));
		})
		.hover (
			function(){
				var cur = $(this).css('backgroundImage');
				$(this).attr('normal_img', cur);
				$(this).css('backgroundImage', 'url(' + $(this).attr('hover_img') + ')');
			},
			function(){
				$(this).css('backgroundImage', $(this).attr('normal_img'));
			}
		)
		.click(function(){
			Popunder.showCurrent();
		});
		//Popunder.show();
	}

	if (page_name == 'summer' || page_name == 'winter') {
		image_preload('images/summer/bird_more2.gif');
		image_preload('images/winter/more_children2.gif');
		$('.more-but')
		.hover(
			function(){
				if (page_name == 'summer') {
					var hover = 'summer/bird_more2.gif';
				} else {
					var hover = 'winter/more_children2.gif';
				}
				var cur = $(this).css('backgroundImage');
				$(this).attr('normal_img', cur);
				$(this).css('backgroundImage', 'url(images/' + hover + ')');
			},
			function(){
				$(this).css('backgroundImage', $(this).attr('normal_img'));
			}
		)
		.click(function() {
			$('.more-text-active').removeClass('more-text-active');
			$('.more-but-active').removeClass('more-but-active');
			$(this).addClass('more-but-active');
			$('.more-text-' + $(this).attr('more-id'))
				//.each(function(){console.dir(this);	})
				.addClass('more-text-active');
		});
	}

	//iframeWrap($('#video'));
	//$('#video').click(function(){alert(1)});
});

MainMenu = {
	image_folder : 'images/menu/',
	getNormalSrc: function(item) {
		return MainMenu.image_folder + item +  '.png';
	},
	getActiveSrc: function (item) {
		return MainMenu.image_folder + item + '2.png';
	},
	getHoverSrc: function(item) {
		return MainMenu.image_folder + item + '2.png';
	},
	itemNormal: function() {
		$(this).css('backgroundImage', 'url(' + MainMenu.getNormalSrc(this.getAttribute('item_name')) + ')');
		//alert($(this).css('backgroundImage'));
	},
	itemActive: function() {
		$(this).css('backgroundImage', 'url(' + MainMenu.getActiveSrc(this.getAttribute('item_name')) + ')');
		$(this).children('a').hide();
	},
	itemOver: function() {
		if ($(this).is('.item_active')) return;
		if ($(this).is('.item_hover')) return;
		$(this).addClass('item_hover');
//			alert($(this).css('backgroundImage'));
		$(this).css('backgroundImage', 'url(' + MainMenu.getHoverSrc(this.getAttribute('item_name')) + ')');
	},
	itemOut: function() {
		if ($(this).is('.item_active')) return;
		if ( ! $(this).is('.item_hover')) return;
		$(this).removeClass('item_hover');
		MainMenu.itemNormal.call(this);
	},
	init: function(){
		/*var preload = [];
		var preload_images = [];*/
		$('#menu div')
		.hover(
			function(){
				MainMenu.itemOver.call(this);
			},
			function(){
				MainMenu.itemOut.call(this);
			}
		)
		.click(function(){
			if (! $(this).is('.item_maps'))
				location.href = $(this).children('a').attr('href');
		})
		.each(function(){
				if ($(this).is('.item_active')) {
					MainMenu.itemActive.call(this);
				} else {
					MainMenu.itemNormal.call(this);
					/*
					preload.push(MainMenu.getNormalSrc(this.getAttribute('item_name')));
					preload.push(MainMenu.getHoverSrc(this.getAttribute('item_name')));
					*/
					image_preload(MainMenu.getNormalSrc(this.getAttribute('item_name')));
					image_preload(MainMenu.getHoverSrc(this.getAttribute('item_name')));
				}
			}
		);
		/*for(var i in preload) {
			var img = new Image();
			img.src = preload[i];
			preload_images.push(img);
		}*/
	}
}


Popunder = {
	images: [
		['images/hotels/popup/img.jpg', 'images/hotels/popup/img_1.jpg', 'images/hotels/popup/img_1a.jpg'],
		['images/hotels/popup/img2.jpg', 'images/hotels/popup/img_2.jpg', 'images/hotels/popup/img_2a.jpg'],
		['images/hotels/popup/img.jpg', 'images/hotels/popup/img_3.jpg', 'images/hotels/popup/img_3a.jpg'],
		['images/hotels/popup/img2.jpg', 'images/hotels/popup/img_4.jpg', 'images/hotels/popup/img_3a.jpg']
	],
	cur_image: 0,
	init: function() {
		$('#popunder .but-close, #popunder-bg').click(function(){
			Popunder.hide();
		})
		$('#popunder .but-left').click(function(){
			Popunder.showPrev();
		});
		$('#popunder .but-right').click(function(){
			Popunder.showNext();
		});
		this.initImages();
	},
	initImages: function () {
		$('#popunder .thumbs').empty();
		var cur_x = 0;
		for (var i = 0; i < this.images.length; i++) {
			$('#popunder .thumbs').append('<div thumb_id="'+i+'"style="left: ' + cur_x + 'px; "></div>');
			cur_x += 37;
		}
		var that = this;
		$('#popunder .thumbs div')
			.each(function(){
				$(this).css('backgroundImage', 'url(' + that.images[$(this).attr('thumb_id')][1] + ")");
			})
			.hover(
				function(){
					$(this).css('backgroundImage', 'url(' + that.images[$(this).attr('thumb_id')][2] + ")");
				},
				function(){
					$(this).css('backgroundImage', 'url(' + that.images[$(this).attr('thumb_id')][1] + ")");
				}
			)
			.click(function(){
				that.cur_image = parseInt($(this).attr('thumb_id'), 10);
				that.showCurrent();
			});
	},
	showCurrent: function(){
		$('#popunder-bg').width($(document.body).width()).height($('#main').height()).show();
		$('#popunder .pu-photo').css('backgroundImage', 'url(' + this.images[this.cur_image][0] + ')');

	    var arrayPageSize = getPageSize();
	    var arrayPageScroll = getPageScroll();
		var myHeight = parseInt($('#popunder').css('height'), 10);
	    var top = arrayPageScroll[1] + (arrayPageSize[3] - myHeight) / 2 ;
	    $("#popunder").css({display:"block", top:top, left:105});
		$('#popunder').show();
	},
	hide: function() {
		$('#popunder, #popunder-bg').hide();
	},
	showPrev: function() {
		this.cur_image = ( (this.cur_image == 0) ? this.images.length - 1 : this.cur_image - 1);
		this.showCurrent();
	},
	showNext: function() {
		this.cur_image = ( (this.cur_image == this.images.length - 1) ? 0 : this.cur_image + 1);
		//alert(this.cur_image);
		this.showCurrent();
	}
}

Popunder_gza = {
	images: [
		['images/gzapop/img_01.jpg', '<p style="font-size:18px; ">Tbilisi</p><p>Tbilisi is a city born of relaxation and warm springs. Its wooden houses, churches, cafes and baths have served as a welcome home from home for travelers for two thousand years. It stands on the banks of the River Mtkvari surrounded by high hills. The word Tbilisi derives from the Georgian \'tbili\' which means warm - referring to the natural mineral water bubbling up from the earth near its 4th century Narikala fortress. Today Tbilisi is a major economic and cultural center - the hub of the Southern Caucasus. But its Old Town will show visitors just why it has grown up in this way - amid a Mediterranean atmosphere and harmonious mixture of architectural styles. '],
		['images/gzapop/img_02.jpg', '<p style="font-size:18px; ">Ananuri Fortress</p><p>The formidable Ananuri fortress dates from the 17th century and incorporates a wall, turrets, large and small churches. Its watch-tower with a stepped pyramidal roof typical of the Caucasus. The single-nave Mkurnali church and bell-tower stand close to a spring and reservoir.<br>The facade is richly adorned with some of ther finest examples of relief carvings, featuring human, animal and floral images.</p>'],
		['images/gzapop/img_03.jpg', '<p style="font-size:18px; ">Mtskheta</p><p>The historical churches of Mtskheta , the ancient capital of Georgia, are outstanding examples of medieval religious architecture. Unesco have declared them a World Cultural Heritage Site.<br>piring Svetitskhoveli ("The Column of Life") Cathedral was built on the site of the first Christian Georgian church, where it is said a local Jew, Sidonia, was buried with the Christ\'s robe in her hands. The magnificent building, used for coronations and burials of Georgian monarchs down through history, is wrapped in a tall fortress wall.<br>Standing on a mountain top high above Mtskheta is the ancient Jvari (Holy Cross) Monastery. Climb up and receive a stunning view of the entire area. See clearly the town\'s strategic location at the confluence of eastern Georgia\'s main rivers, the Aragvi and Mtkvari.</p>'],
		['', '<p style="font-size:18px; ">Gudauri</p><p>For thousands of years the passes and valleys through Gudauri have served as the main route connecting the north and south Caucasus.  In the 19th century this historic artery was reconstructed as the Georgian Military Highway by the engineers of Imperial Russia.   Know as one of the most breathtaking winding mountain roads on the planet, the Military Highway has been celebrated by writers such as Pushkin, Lermontov and Alexander Dumas.</p><p> The Georgian Military Highway traverses the high Caucasus from Russia\'s Vladikavkaz in the north – to Tbilisi. The route is dotted with ancient stone watch-towers, unique medieval churches such as the 17th century Ananouri and fantastic views. Its highest point is the Jvari (Cross) Pass at 2364 metres, at the top of an unforgettable winding climb from the valley depths below.</p>']
	],
	cur_image: 0,
	init: function() {
		$('#pgza .but-close, #popunder-bg').click(function(){
			Popunder_gza.hide();
		});
		$('#pgza .but-left').click(function(){
			Popunder_gza.showPrev();
		});
		$('#pgza .but-right').click(function(){
			Popunder_gza.showNext();
		});
	},

	showCurrent: function(){
		$('#popunder-bg').width($(document.body).width()).height($('#main').height()).show();
		//alert(this.images[this.cur_image][0]);

		if (this.images[this.cur_image][0] == '') {
			$('#pgza .place-text2').css('display', 'none');
			var photo = document.getElementById('pgza-photo-wrapper');

			photo.style.visibility = 'hidden';
			//alert(photo.style.visibility);
			//alert(document.getElementById('pgza-photo-wrapper').style.display);
			$('#pgza .place-text').show().html(this.images[this.cur_image][1]);
			//alert(1);
		} else {
			//alert(2);
			$('#pgza .place-text').hide();
			$('#pgza .place-text2').css('display', 'block').html(this.images[this.cur_image][1]);
			document.getElementById('pgza-photo-wrapper').style.visibility = 'visible';
			$('#pgza .photo').css('backgroundImage', 'url(' + this.images[this.cur_image][0] + ')');
			//$('#pgza .photo-wrapper *').show();
		}

	    var arrayPageSize = getPageSize();
	    var arrayPageScroll = getPageScroll();
		var myHeight = parseInt($('#pgza').css('height'), 10);
	    var top = arrayPageScroll[1] + (arrayPageSize[3] - myHeight) / 2 - 80;
	    $("#pgza").css({display:"block", top:top, left:105});
		$('#pgza').show();
	},
	hide: function() {
		$('#pgza, #popunder-bg').hide();
	},
	showPrev: function() {
		this.cur_image = ( (this.cur_image == 0) ? this.images.length - 1 : this.cur_image - 1);
		this.showCurrent();
	},
	showNext: function() {
		this.cur_image = ( (this.cur_image == this.images.length - 1) ? 0 : this.cur_image + 1);
		//alert(this.cur_image);
		this.showCurrent();
	}
}
Scrapbook = {
	images: [
		['images/popup/photo/01.jpg'],
		['images/popup/photo/03.jpg'],
		['images/popup/photo/04.jpg'],
		['images/popup/photo/05.jpg'],
		['images/popup/photo/06.jpg'],
		['images/popup/photo/07.jpg'],
		['images/popup/photo/08.jpg'],
		['images/popup/photo/09.jpg'],
		['images/popup/photo/11.jpg'],
		['images/popup/photo/12.jpg'],
		['images/popup/photo/13.jpg'],
		['images/popup/photo/14.jpg'],
		['images/popup/photo/15.jpg'],
		['images/popup/photo/16.jpg'],
		['images/popup/photo/17.jpg'],
		['images/popup/photo/18.jpg'],
		['images/popup/photo/19.jpg'],
		['images/popup/photo/20.jpg'],
		['images/popup/photo/21.jpg'],
		['images/popup/photo/22.jpg'],

		['images/popup/photo/IKA_0018.JPG'],
		['images/popup/photo/IKA_0057.JPG'],
		['images/popup/photo/IMG_4995.JPG'],
		['images/popup/photo/IMG_5018.JPG'],

		['images/popup/photo/23.jpg']
	],
	cur_image: 0,
	el : null,
	init: function() {
		var that = this;
		this.el = $('#scrap');
		$('#popunder-bg').add(this.el.find('.but-close')).click(function(){
			that.hide();
		})

		this.el.find('.but-left').click(function(){
			that.showPrev();
		});
		this.el.find('.but-right').click(function(){
			that.showNext();
		});
		this.initImages();
	},
	initImages: function () {
	},
	showCurrent: function(){
		$('#popunder-bg').width($(document.body).width()).height($('#main').height()).show();
		this.el.find('.photo').css('backgroundImage', 'url(' + this.images[this.cur_image][0] + ')');

	    var arrayPageSize = getPageSize();
	    var arrayPageScroll = getPageScroll();
		var myHeight = parseInt(this.el.css('height'), 10);
	    var top = arrayPageScroll[1] + (arrayPageSize[3] - myHeight) / 2 - 80;
	    this.el.css({display:"block", top:top, left:105});
		this.el.show();
	},
	hide: function() {
		$('#popunder-bg').add(this.el).hide();
	},
	showPrev: function() {
		this.cur_image = ( (this.cur_image == 0) ? this.images.length - 1 : this.cur_image - 1);
		this.showCurrent();
	},
	showNext: function() {
		this.cur_image = ( (this.cur_image == this.images.length - 1) ? 0 : this.cur_image + 1);
		//alert(this.cur_image);
		this.showCurrent();
	}
}


function getPageScroll() {
    var yScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        yScroll = document.documentElement.scrollTop;
    } else if (document.body) {
        yScroll = document.body.scrollTop;
    }
    arrayPageScroll = new Array("", yScroll);
    return arrayPageScroll;
}

function getPageSize() {
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) {
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else {
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) {
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) {
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }
    if (xScroll < windowWidth) {
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }
    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
    return arrayPageSize;
}

preload_array = [];
function image_preload(src) {
	var img = new Image();
	img.src = src;
	preload_array.push(img);
}

function  iframeSwitch()
{
	//return;
	//find flash content container and grab contents
	//(should only be object and embed tags)
	var container = $("#pano");
	container.show();
	//console.dir(container);
	var c = container.html();
	if (c == '') return;
	clearInterval(flash_intId);
	c = '<style> body{margin:0}</style>'+c;

	//get the size from the object element
	var object = $("embed",container);
	var x = object.width();
	var y = object.height();

	//create the iframe element, hidden for now
	var frame = $.IFRAME({
		id:'graph_content_frame',
		frameborder:'0',
		marginwidth:'0',
		marginheight:'0',
		scrolling:'no'
	});
	$(frame).css('display','none');

	//attach the iframe to the document and remove the
	//old flash container element
	container.after(frame).remove();

	//set the size, open the iframe, and insert
	//the flash content.
	$("#graph_content_frame")
	.css('border','none')
	.height(y+'px')
	.width(x+'px')
	.css('display','block')
	.each(function(){
		this.contentDocument.open();
		this.contentDocument.write(c);
		this.contentDocument.close();
	});
}

function iframeWrap(el) {
	var inner_html = $(el)[0].innerHTML;
	alert(inner_html);
	var frame = $.IFRAME({
		frameborder:'0',
		marginwidth:'0',
		marginheight:'0',
		scrolling:'no',
		width: '100%',
		height: '100%'
	});
	$(el)
		.empty()
		.append(frame);

	frame.contentDocument.open();
	frame.contentDocument.write(inner_html);
	frame.contentDocument.close();
}

function object(o) {
	function F() {}
	F.prototype = o;
	return new F();
}


Banners = {
	banners: [],
	nextImage: function (el) {

		//console.log(1);
		var cur = 0;
		var count = 0;
		var next = 0;
		var new_image;
		var cur_image;
		//for (var i = 0;  i < this.banners.length; i++ ) {
		count = el.find('.anim-image').length;
		if (count == 1) return;
		cur = Number(el.attr('image-cur'));
		cur_image = $(el.find('.anim-image')[cur]);
		next = (cur == (count - 1)) ? 0 : cur + 1;
		new_image = $(el.find('.anim-image')[next]);

		new_image.css('opacity', 0);
		cur_image.css('zIndex', 1);
		new_image.css('zIndex', 2).animate({'opacity': 1}, 1500);

		/*
		cur_image.animate({opacity: 0}, 1000);
		new_image.animate({opacity:  1}, 1000);
		*/
		//cur_image.removeClass('cur-image');
		//new_image.addClass('cur-image');
		el.attr('image-cur', '' + next);
		//}
	},
	init: function() {
		var that = this;
		$('.anim ').each(function(){
			$(this).find('.anim-image:first').addClass('cur-image');
			$(this).attr('image-cur', '0');
		});


		this.banners = $('.anim');

		setInterval(function(){
			that.nextImage($('#banner1'));

			setTimeout(function(){
				that.nextImage($('#banner2'));
			}, 1500);

			setTimeout(function(){
				that.nextImage($('#banner3'));
			}, 3000);

			setTimeout(function(){
				that.nextImage($('#banner4'));
			}, 4500);

		}, 7000);


		/*var animDelay = 6000;
		setTimeout(function(){
			setInterval(function(){
				that.nextImage($('#banner1'));
			}, animDelay);
		}, 1000);

		setTimeout(function(){
			setInterval(function(){
				that.nextImage($('#banner2'));
			}, animDelay);
		}, 2000);

		setTimeout(function(){
			setInterval(function(){
				that.nextImage($('#banner3'));
			}, animDelay);
		}, 3000);

		setTimeout(function(){
			setInterval(function(){
				that.nextImage($('#banner4'));
			}, animDelay);
		}, 4000);*/
	}
}
