$(function(){	
	$('a').click(function(){
		this.blur();
	});

	var at = 250; // animation time
	
	// ie fuckers
	if($.browser.msie){
		var version = parseInt($.browser.version);
		if(version <= 7){
			at = 0;
			// workaround for table-cell displaeyd li in menu
			$('#navi_1 > .nav_1 > li > .nonpage').each(function(){
				if($(this).html().length < 25){
					$(this).css({
						'padding-top':'104px',
						'height': '25px'
					});
				}
			});	
			$('#navi_1 ul.nav_2 > li > a > span').each(function(){
				if($(this).html().length > 25){
					$(this).css({
						'line-height':'13px'
					});
					$(this).parent('a').css({
						'padding-top':'2px'
					})
				}
			})
			
			if(version == 6){
				$('.nonpage').parent('li').hover(function(){
					$(this).children('ul').css({'display':'block','height':'300px'});
				},function(){
					$(this).children('ul').css('display','none');
				});
				
				$('#navi_1 ul.nav_2 li').hover(function(){
					$(this).toggleClass('hover');
				})
			}
		}
		
		// tabs...
		var first = true;
		var first2 = true;
		
		$('#tabcont > li > a').each(function(){
			txt = $(this).attr('href');
			$(txt).addClass('tab').children('h3:first').css('display','none');
			if(window.location.hash.length > 0){
				var hash = window.location.hash;
				if(hash == txt){
					$(this).addClass('active');
				}else{
					$(txt).css('display','none');
				}
			}else{
				if(first){
					first = false;
					$(this).addClass('active');
				}else{
					$(txt).css('display','none');
				}
			}
		});
		
		$('.subtabcont').each(function(){
			first2 = true;
			$(this).children('li').children('a').each(function(){
				txt = $(this).attr('href');
				$(txt).addClass('tab2');
					if(first2){
						first2 = false;
						$(this).addClass('active');
					}else{
						$(txt).css('display','none');
					}
			});
		});
		
		$('.tab h2:first, .tab h3:first').css('display','none');
		
		$('#tabcont a').click(function(e){
			txt = $(this).attr('href');
			$('.tab').css('display','none');
			$(txt).css('display','block');
			$('#tabcont a').removeClass('active');
			$(this).addClass('active');
			//e.preventDefault();
		});
		
		$('.subtabcont a').click(function(e){
			txt = $(this).attr('href');
			//alert(txt);
			$('.tab2').css('display','none');
			$(txt).css('display','block');
			$('.subtabcont a').removeClass('active');
			$(this).addClass('active');
			e.preventDefault();
		});
		
		$('#tabcont a.active, .subtabcont a.active').click(function(e){
			e.preventDefault();
		})
		
	}else{
		// tabs...
		var first = true;
		var first2 = true;
		
		$('#tabcont > li > a').each(function(){
			txt = $(this).attr('href');
			$(txt).addClass('tab').children('h3:first').css('display','none');
			if(window.location.hash.length > 0){
				var hash = window.location.hash;
				if(hash == txt){
					$(this).addClass('active');
				}else{
					$(txt).css('display','none');
				}
			}else{
				if(first){
					first = false;
					$(this).addClass('active');
				}else{
					$(txt).css('display','none');
				}
			}
		});
		
		$('.subtabcont').each(function(){
			first2 = true;
			$(this).children('li').children('a').each(function(){
				txt = $(this).attr('href');
				$(txt).addClass('tab2');
					if(first2){
						first2 = false;
						$(this).addClass('active');
					}else{
						$(txt).css('display','none');
					}
			});
		});
		
		$('.tab h2:first, .tab h3:first').css('display','none');
		
		$('#tabcont a').click(function(e){
			txt = $(this).attr('href');
			$('.tab:not(:hidden):not('+txt+')').slideUp(at,function(){
				$('.tab2:not(:hidden)').css('display','none');
				
				$(txt).slideDown(at);
			});
			$('#tabcont a').removeClass('active');
			$(this).addClass('active');
			//e.preventDefault();
		});
		
		$('.subtabcont a').click(function(e){
			txt = $(this).attr('href');
			//alert(txt);
			$('.tab2:not(:hidden):not('+txt+')').slideUp(at,function(){
				$(txt).slideDown(at);
			});
			$('.subtabcont a').removeClass('active');
			$(this).addClass('active');
			e.preventDefault();
		});
		
		$('#tabcont a.active, .subtabcont a.active').click(function(e){
			e.preventDefault();
		})
	}
	
	// faq
	if($('#faq').length){
		// doctor switcher
		var img_counter = 0
		$('#faq_doc img').each(function(){
			if(img_counter != 0){
				$(this).hide();
			}
			++img_counter;
		});
		var img_count = img_counter;
		img_counter = 0;
		var nextImage = function(){
			$('.img'+img_counter).delay(2500).fadeOut(1500,function(){
				++img_counter;
				if(img_counter == img_count){
					img_counter = 0;
				}
				$('.img'+img_counter).fadeIn(1500,function(){
					nextImage();
				});
			});
		}
		nextImage();
		
		// show/hide answers
		$('#faq .answer').css('display','none');
		$('#faq .show_answer')
			.css('display','block')
			.click(function(e){
				e.preventDefault();
				$('#faq_doc:not(:hidden)').slideUp(50).children().stop();
				$(this).slideUp(); // hide show reply link
				$('#faq .answer:not(:hidden)').slideUp().siblings('.show_answer').slideDown(); // hide visible answers
				$(this).siblings('.answer').slideDown(); // show answer
			});
	}
	
	
	
	
	

	
	
	// intro	
	if($('#intro').length != 0){
		var overlay = $('#overlay');
		var intro = $('#intro')
		var doc = $(document);
		var win = $(window);
		var fdtm = 3000; // fade time
		var img_count = 1;
		
		var introEnd = function(e){
			intro.css('display','none');
			overlay.css('display','none');
			e.preventDefault();
		}
		
		$('#skip_intro').click(function(e){
			//$('#intro > img').stop();
			introEnd(e);
		});
		
		overlay.css({
			width: doc.width()+'px',
			height: doc.height()+'px',
			display: 'block'
		});
		
		intro.css({
			'margin-left' : parseInt((win.width()-intro.width())/2),
			'margin-top': 28+'px', //parseInt((win.height()-intro.height())/3),
			display: 'block'
		});
		
		
		$('body').animate({'width':'100%'}, 13500,function(){
			intro.children('#skip_intro').css('display','none');
			intro.children('object').css('display','none');
			intro.animate({'opacity':'0'},fdtm);
			overlay.animate({'opacity':'0'},fdtm,function(){
				intro.css('display','none');
				overlay.css('display','none');
			})
		});
	}
	
});

