/** 
 * Finansbank Private Banking Javascript File.
 * Generated by www.igoa.in for www.finansbank.com.tr
 * @author Mustafa ARTUC
 * @email mustafa@igoa.in
 */
$(document).ready(function(){
	var userAgent = navigator.userAgent.toLowerCase();
	$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
	var version = 0;
	
	if($.browser.chrome || $.browser.safari){
		userAgent = userAgent.substring(userAgent.indexOf('chrome/') +7);
		userAgent = userAgent.substring(0,userAgent.indexOf('.'));
		version = userAgent;
		var newsList = false;
	}else{
		newsList = true;
	}

	//News without link
	$("a[href='#nolink']").addClass("noLink");
	$("a[href='#nolink']").click(function(){
		return false;
	});
	
	//MainPage Tabs
	$(".tabsContainer a").live('click',function(){
		if(!$(this).hasClass('selectedTab')){
			$('.selectedTab').removeClass('selectedTab');
			$('.selectedContent').hide().removeClass('selectedContent');
			$(this).addClass('selectedTab');
			$('.'+$(this).attr('href')).fadeIn().addClass('selectedContent');		
		}
		return false;
	});
	
	//NewsList ScrollBar Stuff
	$('.newsList').css('width', ($('.newsList li').length*141));
	if(newsList)
		$(".newsListWrapper").customScroller(); //Main Scroller Script.
	
	//Left Menu
	$(".subMenuOpener").mouseover(function(){
		$(this).find('.subMenuContainer').fadeIn();
		$(this).find('a:first').css('color', 'black');
	}).mouseleave(function(){
		$(this).find('.subMenuContainer').fadeOut();
		$(this).find('a:first').css('color', 'white');
	});
	
	//Content Gallery
	if($('.contentGallery li').length < 3)
		$('.galleryNext, .galleryPrev').hide();

	var currentImage = 0;
	$('.contentGalleryContainer .contentGallery').css('width', $('.contentGalleryContainer .contentGallery li').length * 438);	
	$('.galleryNext').click(function(){
		if(currentImage < $(".contentGallery li").length-2){
			galleryPosition = $(".contentGallery").position();
			newPosition = parseInt(galleryPosition.left)-438;
			
			$('.contentGallery').animate({left: newPosition+'px'},
			{duration: 'fast'});
			
			currentImage = currentImage+1;
		}else{
			currentImage = 0;
			$('.contentGallery').animate({left: '0px'},
			{duration: 'fast'});
		}
		return false;
	});
	
	$('.galleryPrev').click(function(){
		if(currentImage != 0){
			galleryPosition = $(".contentGallery").position();
			newPosition = parseInt(galleryPosition.left)+438;
			
			$('.contentGallery').animate({left: newPosition+'px'},
			{duration: 'fast'});
			
			currentImage = currentImage-1;
		}else{
			currentImage = 0;
			$('.contentGallery').animate({left: '0px'},
			{duration: 'fast'});
		}
		
		return false;
	});
	
	//Spot Image Close Button.
	$('.btnCloseSpot').click(function(){
		$('.headerFlyerContainer').fadeOut();
		return false;
	});

	//Accordion - artuc: 21.06.2010
	$(".financeAccordion li h3").click(function(){
		if(!$(this).hasClass('selectedTab')){	
			$(".selectedTab").removeClass("selectedTab");
			$(this).addClass("selectedTab");
			$(this).parent().find("div").addClass("selectedAccordionContent").slideDown();
		}else{
			$(".selectedTab").removeClass("selectedTab");
			$(".selectedAccordionContent").slideUp();
			$(".selectedAccordionContent").removeClass("selectedAccordionContent");
		}
	});

	//Main Page Tab Auto Changer - artuc: 21.06.2010
	if(!($('body').hasClass('en')))
		var changeTabInterval = setInterval(changeTab, 8500);
	
	//Finansbank Links Open
	$(".tr .btnContainer a.internetSube").click(function(){
		LeftPosition = (screen.width) ? (screen.width-983)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-598)/2 : 0;
		window.open('https://intbank.finansbank.com.tr/FWF/login.jsp', "finansbankInternet","menubar=0,scrollbars=1,resizable=0,width=983,height=598, left="+LeftPosition+",top="+TopPosition+"scrollbars=yes");
		return false;
	});

	$(".tr .btnContainer a.creaditCardBranch").click(function(){
		LeftPosition = (screen.width) ? (screen.width-525)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-368)/2 : 0;
		window.open('https://kredikartisubesi.finansbank.com.tr/FWFWEB/loginKOS.jsp', "finansbankInternet","menubar=0,scrollbars=1,resizable=0,width=525,height=368, left="+LeftPosition+",top="+TopPosition+"scrollbars=yes");
		return false;
	});
	
	$(".en .btnContainer a.internetSube").click(function(){
		LeftPosition = (screen.width) ? (screen.width-983)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-598)/2 : 0;
		window.open('https://intbank.finansbank.com.tr/FWF/loginEN.jsp', "finansbankInternet","menubar=0,scrollbars=1,resizable=0,width=983,height=598, left="+LeftPosition+",top="+TopPosition+"scrollbars=yes");
		return false;
	});
	
	$(".tr .btnContainer a.internetSifre").click(function(){
		LeftPosition = (screen.width) ? (screen.width-620)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-598)/2 : 0;
		window.open('http://www.finansbank.com.tr/hizli_basvuru/popup_islemkolay_internet_basvuru.aspx', "finansbankInternet","menubar=0,scrollbars=1,resizable=0,width=620,height=598,left="+LeftPosition+",top="+TopPosition+"scrollbars=yes");
		return false;
	});

	//Contact Field Filters
	$("#firstName, #lastName, #alreadyBrunch").live('keypress', function(e){ return alpha(e,letters); });
	$("#phoneNum1AreaCode, #phoneNum1, #phoneNum2AreaCode, #phoneNum2, #customerNo").live('keypress', function(e){ return alpha(e,numbers); });

	$('.btnCaptchaRefresh').click(function(){
		var srcImg = $('.captchaContainer img').attr('src')+'&v='+new Date().getTime();
		$('.captchaContainer img').attr('src', '');
		$('.captchaContainer img').attr('src', srcImg);

		return false;
	});
	equalHeight();
	var m = setTimeout("equalHeight()",5000);
	
	/**
	 * @author: artuc:
	 * 19.04 - Content Tabs implementations
	 * 
	 * */
	
	$('.subTabs li a').click(function(){
		$('.selectedContentTab').removeClass('selectedContentTab', 'slow');
		$(this).addClass('selectedContentTab');
		
		$('.tab-content').hide();
		$($(this).attr('href')).show();
		
		return false;
	});
});


function equalHeight(){
	elemCount0 = $('.column0 .activityItem').length;
	elemCount1 = $('.column1 .activityItem').length;
	elemCount2 = $('.column2 .activityItem').length;
	elemCount3 = $('.column3 .activityItem').length;
	
	$(".column0").css("height", (elemCount0 * 205)+'px');
	$(".column1").css("height", (elemCount1 * 205)+'px');
	$(".column2").css("height", (elemCount2 * 205)+'px');
	$(".column3").css("height", (elemCount3 * 205)+'px');

	col0 = $(".column0").outerHeight();
	col1= $(".column1").outerHeight();
	col2 = $(".column2").outerHeight();
	col3 = $(".column3").outerHeight();

	myNum = Math.max(col0,col1,col2,col3);
	$(".column0").css("height", myNum+"px");
	$(".column1").css("height", myNum+"px");
	$(".column2").css("height", myNum+"px");
	$(".column3").css("height", myNum+"px");
}

function changeTab(){
	$('.financialInfo .tabsContainer li a').each(function(){
		if(!$(this).hasClass('selectedTab')){
			$('.selectedTab').removeClass('selectedTab');
			$('.selectedContent').hide().removeClass('selectedContent');
			$(this).addClass('selectedTab');
			$('.'+$(this).attr('href')).fadeIn().addClass('selectedContent');		
			return false;			
		}
	});
}

//Contact Input Filters
var letters=' ABCÇDEFGĞHİIJKLMNOÖPQRSŞTUÜVWXYZabcçdefgğhıijklmnöopqrsştüuvwxyz'
var numbers='1234567890'
var signs=',.:;@-\''
var mathsigns='+-=()*/'
var custom='<>#$%&?¿'

function alpha(e,allow) {
	var unicode=e.charCode? e.charCode : e.keyCode;
	if(unicode!="9"){
		if(unicode != "8"){
			var k;
			k=document.all?parseInt(e.keyCode): parseInt(e.which);
			return (allow.indexOf(String.fromCharCode(k))!=-1);
		}
	}
}
