/***************************
**** CREATE: 13.07.2011 ****
****** VERSION: 1.0.4 ******
***************************/

Cufon.replace(".HeliosBlack,:header", { fontFamily: 'HeliosBlack', hover: true});
Cufon.replace(".HeliosBold", { fontFamily: 'HeliosBold', hover: true});
Cufon.replace(".MyriadPro", { fontFamily: 'MyriadPro', hover: true});

$.fn.placeholder = function(){
	this.each(function(){
		$(this).attr('defaultvalue',$(this).val()).focus(function(){
			if($(this).val() == $(this).attr('defaultvalue'))
				$(this).val('');
		}).blur(function(){
			if($(this).val() == '')
				$(this).val($(this).attr('defaultvalue'));
		});
	});
}

$.fn.pie = function(a){
	if (window.PIE && $.browser.msie) {
		if(a === 'remove')
		{
			this.each(function() {
				PIE.detach(this);
			});
		} else
		{
			this.each(function() {
				PIE.attach(this);
			});
		}
	}
	return this;
}

function overlay(act){
	var overlay = $('#sm_overlay');
	if(act === 'hide'){
		overlay.hide();
		return false;
	}
	if(!overlay.length)
	{
		$('<div id="sm_overlay" class="sm_overlay"></div>').appendTo('body');
		overlay = $('#sm_overlay');
	}
	overlay.css({height:$('body').height(),opacity:0.5}).show();
}

$(function() {
	if ($('#promoblock').length){
		$('#promoblock a').hover(function() {
			if (!$(this).closest('li').hasClass('active')) {
				$('#promoblock li.active').removeClass('active');
				$(this).closest('li').addClass('active');
				return false;
			}
		});
	}

	if ($('.timeline').length) {
		var TIMELINE_SLIDER_SLIDE_SPEED = 500;
		var TIMELINE_SLIDER_SLIDE_OFFSET = 150;
		var timeline = $('.timeline');
		var timeline_slider = $('ul',timeline);
		var timeline_slider_items = $('li',timeline_slider);
		var TIMELINE_SLIDER_ITEM_WIDTH = 73;
		var	timeline_slider_width = timeline_slider_items.length * TIMELINE_SLIDER_ITEM_WIDTH;
		timeline_slider.css({'width':timeline_slider_width });
		var timeline_slider_visible_area = $('.timeline_list_wrapper',timeline);
		var timeline_prev_button = $('.prev',timeline);
		var timeline_next_button = $('.next',timeline);
		var timeline_slide_ready = true;

			if (timeline_slide_ready & timeline_slider_items.filter('.active').index() > 2) {
				timeline_slide_ready = false;
				timeline_slider.animate({
					left: '-=' + ((timeline_slider_items.filter('.active').index() - 3) * 53)
				}, TIMELINE_SLIDER_SLIDE_SPEED, function() {
					/* set buttons status */
					timeline_slide_ready = true;
				});
			}


		function getTimelineSliderLeftSpace() {
			timeline_slider_left_offset = Math.abs(parseInt(timeline_slider.css('left')));
			if (timeline_slider_left_offset >= TIMELINE_SLIDER_SLIDE_OFFSET) {
				return TIMELINE_SLIDER_SLIDE_OFFSET;
			} else {
				return timeline_slider_left_offset;
			}
		}

		function getTimelineSliderRightSpace() {
			timeline_slider_right_offset = timeline_slider.width() - timeline_slider_visible_area.width() - Math.abs(parseInt(timeline_slider.css('left')));
			if (timeline_slider_right_offset >= TIMELINE_SLIDER_SLIDE_OFFSET) {
				return TIMELINE_SLIDER_SLIDE_OFFSET;
			} else {
				return timeline_slider_right_offset;
			}
		}

		timeline_prev_button.click(function() {
			if (!$(this).hasClass('disabled') && timeline_slide_ready) {
				timeline_slide_ready = false;
				timeline_slider.animate({
					left: '+=' + getTimelineSliderLeftSpace()
				}, TIMELINE_SLIDER_SLIDE_SPEED, function() {
					/* set buttons status */
					timeline_slide_ready = true;
				});
			}
			return false;
		});

		timeline_next_button.click(function() {
			if (!$(this).hasClass('disabled') && timeline_slide_ready) {
				timeline_slide_ready = false;
				timeline_slider.animate({
					left: '-=' + getTimelineSliderRightSpace()
				}, TIMELINE_SLIDER_SLIDE_SPEED, function() {
					/* set buttons status */
					timeline_slide_ready = true;
				});
			}
			return false;
		});

	}

	var next_menu_list;
	$('.header .menu li').hover(function() {
		next_menu_list = $(this).next();
		next_menu_list.addClass('no_background');
	},function() {
		next_menu_list.removeClass('no_background');
	});

	if ($('.hint').length && $('#hint_popup').length) {
		var hint_popup = $('#hint_popup');
		var hint_popup_content = $('#hint_popup_content');
		$('.hint').hover(function(event) {
			hint_popup.css({'display':'block'});
			hint_popup_content.html($(this).attr('alt_text'));
			hint_popup.css({
				'margin-top':0 - hint_popup.height() - 30,
				'top':event.pageY,
				'left':event.pageX
			});
			hint_popup.css({'visibility':'visible'});
		},function(event) {
			hint_popup.css({'visibility':'hidden','display':'none'});
		}).mousemove(function(event) {
			hint_popup.css({
				'top':event.pageY,
				'left':event.pageX
			});
		});
	}


	if ($('.faq').length) {
		$('.faq .faq_header a').click(function() {
			if($(this).closest('li').hasClass('active'))
			{
				$(this).closest('li').removeClass('active');
				return false;
			}
			$('.faq li').removeClass('active');
			$(this).closest('li').toggleClass('active');
			return false;
		});
		$('.faq .open_all').click(function() {
			if ($(this).hasClass('active')){
				$('.faq li').removeClass('active');
				$(this).removeClass('active');
			} else {
				$('.faq li').addClass('active');
				$(this).addClass('active');
			}
			return false;
		});
	}

	$('#fill_form_link').click(function() {
		$('#feedback_form').slideToggle('500');
		return false;
	});

	if ($('.tab-right').length) {
		var animating = false;
		tab_right = $('.tab-right');
		tab_right_nav = $('.nav',tab_right);
		if (!$('li.active',tab_right_nav).length) {
			$('li:first',tab_right_nav).addClass('active');
			Cufon.refresh();
		}		
		slide_top = $('.slide_top',tab_right);
		slide_bottom = $('.slide_bottom',tab_right);
		$('li:first',slide_top).css('display','block');
		$('li:first',slide_bottom).css({
			'display':'block',
			'visibility':'visible'
		});

		function slideTo(index) {
			current_active_tab = $('li.active',tab_right_nav);
			if (current_active_tab.index() !== index && !animating) {
				current_visible_top_slide = $('li:visible',slide_top);
				current_visible_bottom_slide = $('li:visible',slide_bottom);
				animating = true;
				if (current_active_tab.index() > index)	{
					current_visible_top_slide.animate({'left':300},500,function() {
						$(this).css({'display':'none'});
					});
					$('li',slide_top).eq(index).css({'left':-300,'display':'block'}).animate({'left':0},500);
					current_visible_bottom_slide.animate({'left':350},500,function() {
						$(this).css({'display':'none'});
					});
					current_slide = $('li',slide_bottom).eq(index);
					/*current_slide.css('display','block');
					slide_bottom.css('height',current_slide.height());*/
					current_slide.css({'left':-350,'display':'block'}).animate({'left':0},500,function() {
						current_active_tab.removeClass('active');
						$('li',tab_right_nav).eq(index).addClass('active');
						Cufon.refresh();
						animating = false;
					});				
				} else {
					current_visible_top_slide.animate({'left':-300},500,function() {
						$(this).css({'display':'none'});
					});
					$('li',slide_top).eq(index).css({'left':300,'display':'block'}).animate({'left':0},500);
					current_visible_bottom_slide.animate({'left':-350},500,function() {
						$(this).css({'display':'none'});
					});
					current_slide = $('li',slide_bottom).eq(index);
					/*current_slide.css('display','block');
					slide_bottom.css('height',current_slide.height());*/
					current_slide.css({'left':350,'display':'block'}).animate({'left':0},500,function() {
						current_active_tab.removeClass('active');
						$('li',tab_right_nav).eq(index).addClass('active');
						Cufon.refresh();
						animating = false;
					});
				}
			}			
		}

		$('li',tab_right_nav).click(function(e) {
			if(e.originalEvent) clearInterval(ffffggggg);
			window['rightNavLi'] = $(this).index();
			slideTo(window['rightNavLi']);
			return false;
		});


		var ffffggggg;

		function ffggfgfg(){
			ffffggggg = setTimeout(function(){

				if(window['rightNavLi'] == 0 || !window['rightNavLi'])
					$('li',tab_right_nav).eq(1).trigger('click');
				else if(window['rightNavLi'] == 2)
					$('li',tab_right_nav).eq(0).trigger('click');
				else
					$('li',tab_right_nav).eq(2).trigger('click');
				ffggfgfg();
			},5000);
		}
		ffggfgfg();

		$('.left',tab_right).click(function() {
			if ($('li.active',tab_right_nav).prev().length) {
				slideTo($('li.active',tab_right_nav).prev().index());
			}
			return false;
		});
		$('.right',tab_right).click(function() {
			if ($('li.active',tab_right_nav).next().length) {
				slideTo($('li.active',tab_right_nav).next().index());
			}
			return false;
		});
	}	

});

function ShowPhoto(str,x,y,name,url){
	if (str=='') {
		newWindow = window.open(url,'mywindow','width=800,height=600');
	} else{
		if(y < (screen.availHeight - 20) )str3="scrollbars=no,status=no,resizable=yes,width="+x+",height="+y+",left="+(screen.availWidth-x)/2+",top="+(screen.availHeight-y)/2;
		else str3="scrollbars= yes,width="+x+",height="+ (screen.availHeight - 50)  +",left="+(screen.availWidth-x)/2+",top= 10";
		newWindow = window.open("","newWindow",str3);
		newWindow.document.open();
		newWindow.resizeTo( (x/1+70), (y/1+170) );
		newWindow.document.write('<html><title> '+name+'</title><head><meta http-equiv="content-type" content="text/html; charset=UTF-8" /><link rel="stylesheet" href="/css/new_fox.css" type="text/css"></head> <body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" >');
		newWindow.document.write('<table border="0" cellspacing="0" cellpadding="0" align="center" height="100%"><tr><td><center>');
		if (url=='') {
			newWindow.document.write('<img src="'+str+'" width="'+x+'" height="'+y+'" alt="'+name+'" ><br clear="all"><i>'+name+'</i>');
		} else {
			newWindow.document.write('<img border=0 src="'+str+'" width="'+x+'" height="'+y+'" alt="'+name+'" > <center><div style="width:60%">'+name+'</div></center>');
		}
		newWindow.document.write('</div>');
		newWindow.document.write('</center></td></tr></table></body></html>');
		newWindow.document.close();
		newWindow.focus();
	}
}
