﻿/* ----------------------------------------------------------
  
  Project 	: TOBB Web Portal 					|  www.tobb.org.tr
  Author	: Locksmith Software Technologies 	|  www.lstyazilim.com 
  Edit 		: 25.02.2011
  
  ---------------------------------------------------------- */

$(function(){
	$('#navigation-container .navigation li').dropdown();
	$('a.colorbox').colorbox({innerWidth:"75%"});
	
	$('.datepicker').datepicker();
	
	if($('#s4-ribbonrow').hasClass('s4-ribbonhidetitle')){$(this).css('height','25px');}

	/* LANGUAGE & LOGO BIND */
    var substrURL = window.location.pathname.split('/'),
    	sc		= substrURL.length;
	$('#header-container h1').attr('class','tr');
	for(i=0;i<=sc-1;i++){
		if(substrURL[i] == "Eng"){
			$('#wrapper').addClass('eng');			
			$('#header-container h1').attr('class','eng');
			$('#footer-bottom .right').html('Dumlupýnar Bulvarý No:252 (Eskiþehir Yolu 9.Km) 06530 /ANKARA Phone:+90(312) 218 20 00 (PBX) Fax: +90(312) 219 40 90-93<br/>All rights reserved.© 2010 The Union of Chambers and Commodity Exchanges of Turkey');
			$('#search-container b').html('SEARCH');
			$('#header-container .horizontal-menu a').each(function(){
				var lc = $(this).html();
				if(lc == 'ANA SAYFA'){$(this).text('MAIN PAGE');$(this).attr('href','/Sayfalar/Eng/AnaSayfa.aspx');}
				if($(this).attr('href') == '/Sayfalar/Iletisim.aspx'){$(this).text('CONTACT');$(this).attr('href','/Sayfalar/Eng/Iletisim.aspx');}
			});
			
			var sH = $('.eng #subpage-header h2'),
				mH = $('.eng .subpage-menu h3'),
				nH = '';
			switch(substrURL[1]){				
				case 'Baskanimiz':
					nH = 'President';
				break;
				case 'AvrupaBirligiDairesi':
					nH = 'European Union Division';
				break;
				case 'HukukMusavirligi':
					nH = 'Office of Legal Counsellor';
				break;
				case 'BasinMusavirligi':
					nH = 'Press Office';
				break;				
				case 'YayinMudurlugu':
					nH = 'Publications Division';
				break;
				case 'KobiArastirma':
					nH = 'Division of SME Research and Consultancy Center';
				break;
				case 'SanayiMudurlugu':
					nH = 'Industry Division';
				break;
				case 'EgitimveKaliteMudurlugu':
					nH = 'Education and Quality Division';
				break;
				case 'IktisadiRaporlama':
					nH = 'Economic Reporting and Statistics Division';
				break;
				case 'MaliveSosyalPolitikalar':
					nH = 'Fiscal and Social Policies Division';
				break;
				case 'TurkiyeSektorMeclisleri':
					nH = 'Turkish Sector Assembly Division';
				break;
				case 'FuarlarMudurlugu':
					nH = 'Fairs Division';
				break;
				case 'SigortacilikMudurlugu':
					nH = 'Insurance Division';
				break;
				case 'Girisimcilik':
					nH = 'Entrepreneurship Division';
				break;
				case 'OdalarBorsalarDairesi':
					nH = 'Chambers and Commodity Exchanges Department';
				break;
				case 'OdalarMudurlugu':
					nH = 'Chambers Division';
				break;
				case 'BorsalarMudurlugu':
					nH = 'Commodity Exchanges Division';
				break;
				case 'TicaretTirDairesi':
					nH = 'Trade and TIR Department';
				break;
				case 'TirveAtaKarnesi':
					nH = 'TIR and ATA Carnets Division';
				break;
				case 'BilgiHizmetleri':
					nH = 'Information Services Department';
				break;				
				case 'BilgiIslemMudurlugu':
					nH = 'IT Division';
				break;								
				case 'BilgiErisimMudurlugu':
					nH = 'Information Retrieval Division';
				break;												
				case 'YazilimMudurlugu':
					nH = 'Software Division';
				break;												
				case 'TurkiyeTicaretSicilGazetesi':
					nH = 'Turkish Trade Registry Gazette';
				break;																
				case 'DEID':
					nH = 'Foreign Economic Relations Department';
				break;																				
				case 'UluslararasiIlýskiler':
					nH = 'International Relations Division';
				break;																				
				case 'DisTicaretMudurlugu':
					nH = 'Foreign Trade Division';
				break;																		
				case 'AvrupaBirligiDairesi':
					nH = 'European Union Department';
				break;																		
				case 'SatinAlmaveLevazim':
					nH = 'Purchase and Supplies Division';
				break;																		
				case 'IcHizmetlerMudurlugu':
					nH = 'Internal Services Division';
				break;																		
				case 'InsaatveEmlakIsleri':
					nH = 'Construction and Property Affairs Division';
				break;																		
				case 'MuhasebeMudurlugu':
					nH = 'Accounting Division';
				break;																		
				case 'FinansmanMudurlugu':
					nH = 'Finance Division';
				break;																
				case 'PersonelMudurlugu':
					nH = 'Personnel Division';
				break;
				case 'TOBBKadinGirisimcilerKurulu':
					nH = 'Woman Entrepreneurs';
				break;
				case 'TOBBGencGirisimcilerKurulu':
					nH = 'Young Entrepreneurs';
				break;
				case 'ProtokolveOrganizasyon':
					nH = 'Protocol and Organization Division';
				break;
				case 'GlobalStandartlar':
					nH = 'Global Standards Division';
				break;
				case 'UluslararasiIliskiler':
					nH = 'International Relationships Division';
				break;
				case 'GatewayToTurkey':
					nH = 'Gateway To Turkey';
				break;
				case 'IstiraklerMudurlugu':
					nH = 'Affiliates Division';
				break;
			}
			sH.html(nH);
			mH.html(nH);
		}
	}
	
	/* Logo Click Control */
	$('#header-container h1').bind('click',function(){$('#wrapper').hasClass('eng') ? window.location = '/Sayfalar/Eng/AnaSayfa.aspx' : window.location = '/';});
	
	/* SubPage Control */
	if(substrURL[1] != 'Sayfalar'){$('#subpage-header').removeClass('hidden');}

	/* Language Control */			
	$('.lang-container input').bind('click',function(){
		if( $(this).val() == 'ENGLISH' ){OnSelectionChange(1033);}
		else if( $(this).val() == 'TÜRKÇE' ){OnSelectionChange(1055);}
	});

	/* NEWS TABLE */
	$('.news-table tr:odd').addClass('grid-row');
	
	/* FLASH NEWS */
	if($('#flash-news-container').length == 0){$('#content-links-container').removeClass('hidden');}	
	var newsInterval = 5000;	
	$('.fn-photo a:first').show();
	$('.fn-content > div:first').show();
	$('.fn-thumbs a').removeAttr('class');
	$('.fn-thumbs a:first').addClass('current');
	$('.fn-thumbs a:last').css('margin-right','0px');	
	$('.fn-thumbs a').each(function(){
		$(this).bind('click',function(){
			var index = $(this).prevAll().length;
			$('.fn-thumbs a').removeAttr('class');
			$('.fn-content > div').hide();
			$('.fn-photo a').hide();
			$(this).addClass('current');
			$('.fn-content > div:eq('+index+')').fadeIn();
			$('.fn-photo a:eq('+index+')').fadeIn();
			return false;
		});								
	});	
	
	function slideNews(e){
		var currentIndex = $('.fn-thumbs a.current').prevAll().length;
		currentIndex++;
		if(currentIndex == 1 && e == 0){currentIndex = 2;}
		slide = setInterval(function(){
			if(e == 1){currentIndex++;e=0;}
			if(currentIndex == $('.fn-photo a').length + 1 ){currentIndex = 1;}
			$('.fn-thumbs a').removeAttr('class');
			$('.fn-content > div').hide();
			$('.fn-photo a').hide();
			$('.fn-thumbs a:nth-child('+currentIndex+')').attr('class','current');
			$('.fn-content > div:nth-child('+currentIndex+')').fadeIn();
			$('.fn-photo a:nth-child('+currentIndex+')').fadeIn();
			currentIndex++;
		},newsInterval);	
	}
	
	$('.flash-news').mouseenter(function(){
		clearInterval(slide);
	}).mouseleave(function(){
		clearInterval(slide);
      	currentIndex=0;
		slideNews(1);
    });    	
	slideNews(0);	

	/* ACCORDION */	
	$('.accordion-nav > li').each(function(){
		$(' > a', this).bind('click',function(){
			if( $(this).attr('href') == '#'){
				if($(this).attr('class') == 'current')
				{
					$(this).parent().find('ul').slideUp(500);
					$(this).removeAttr('class');
				}
				else
				{
					$('.accordion-nav ul').slideUp();
					$('.accordion-nav a').removeAttr('class');
					$(this).addClass('current');
					$(this).parent().find('ul').slideDown(500);
				}
				return false;
			}
		});
	});

	/* CAROUSEL */
	$('.carousel-contents img').removeAttr('style');	
 	var contentCount = $('.carousel-contents > div').size();
	var newWidth = contentCount * 142;
	var newXPos  = 0;
	var position = 0; /* $('.carousel-contents').position().left */
	$('.carousel-contents').css('width',newWidth);
	if(contentCount <= 1){
		$('.carousel .left a').addClass('passive');
		$('.carousel .right a').addClass('passive');
	}
	else
	{
		$('.carousel .left a').addClass('passive');		
	}
	
	$('.carousel-nav a').bind('click',function(){
		var direction = $(this).attr('rel');

		if(direction == 'right')
		{
			if(newXPos != -(newWidth - 142))
			{
				newXPos = newXPos - 142;
				$('.carousel-contents').animate({left:''+newXPos+'px'},500);	
				$('.carousel .left a').removeAttr('class');
				if(newXPos == -(newWidth - 142))
				{
					$(this).addClass('passive');
					return false;				
				}
			}
		}
		else
		{
			if(newXPos != 0)
			{
				newXPos = newXPos + 142;
				$('.carousel-contents').animate({left:''+newXPos+'px'},500);
				$('.carousel .right a').removeAttr('class');
				if(newXPos == 0)
				{
					$(this).addClass('passive');
					return false;				
				}
			}
		}
		return false;
	});

	/* TAB */	
	$('.announcement-table img').removeAttr('style');	
	var tabCount = $('.tab-nav a').size();
 	$('.tab-nav a:first').addClass('current');
	$('.content-container div div:first').show();
	$('.tab-nav a').bind('click',function(){			
			var no = $(this).attr('id').slice(3,4);
			$('.content-container div div').hide();
			$('.tab-nav a').removeClass('current');
			$(this).addClass('current');		
			$('.content-container div#tc-'+no+'').fadeIn();
			$('.content-container div#tc-'+no+' div').show();	
			return false;
	});

	/* BANNERS */
	$('.banner-container').each(function(){$('div:first',this).addClass('active');});
	
	function bannerSwitch(){
		bannerInterval = setInterval(function(){
			$('.banner-container').each(function(){
				if($('img',this).length > 1){
					var $active = $('div.active',this);
				    if ( $active.length == 0 ){ $active = $('div:last',this);}
				    var $next = $active.next().length ? $active.next() : $('div:first',this);	
				    $active.addClass('last-active');
				    $next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 1000, function(){
				    	$active.removeClass('active last-active');
				    });
				 }
				 else{return false;}			    
		    });		
		},5000);
	}
	
	if($('.banner-container div').length > 1){bannerSwitch();}

	/* HEADER */	
	if($('#header img').length){$('#header').removeAttr('class');}

	/* LITTLE BANNERS */			
	var bannerInterval = 6000;
	$('.banner-box div:first').addClass('current');	
	function autoBannerSlide(){
		bannerSlide = setInterval(function(){
			$thechosenone = $('.banner-box .current');
			$thechosenone.next().css('left','282px');
			$thechosenone.next().animate({left:'0px'},500);
			$thechosenone.animate({left:'-282px'},500);
			$thechosenone.removeClass('current');
			$thechosenone.addClass('last-current');
			$('.banner-box .last-current').next().addClass('current');
			$('.banner-box .last-current').removeClass('last-current');
			$('.banner-box div:first').insertAfter('.banner-box div:last');
		}, bannerInterval);	
	}	
	$('.banners-container').mouseenter(function(){
		clearInterval(bannerSlide);
	}).mouseleave(function(){
		clearInterval(bannerSlide);
		autoBannerSlide();
    });	
	
	if($('.banners-container .banner-box div').length > 1){		
	autoBannerSlide();	
	$('.banners-container .nav a').each(function(){
		$(this).bind('click',function(){
			$thechosenone = $('.banner-box .current');			
			if($(this).attr('class') == 'prev'){				
				$thechosenone.next().css('left','282px');
				$thechosenone.next().animate({left:'0px'},500);
				$thechosenone.animate({left:'-282px'},500);
				$thechosenone.removeClass('current');
				$thechosenone.addClass('last-current');
				$('.banner-box .last-current').next().addClass('current');
				$('.banner-box .last-current').removeClass('last-current');
				$('.banner-box div:first').insertAfter('.banner-box div:last');
			}else{
				$('.banner-box div:last').insertBefore('.banner-box div:first');
				$thechosenone.prev().css('left','-282px');
				$thechosenone.prev().animate({left:'0px'},500);
				$thechosenone.animate({left:'282px'},500);
				$thechosenone.removeClass('current');
				$thechosenone.addClass('last-current');
				$('.banner-box .last-current').prev().addClass('current');
				$('.banner-box .last-current').removeClass('last-current');
			}
			return false;
		});
	});	
	}else{$('.banners-container .nav').hide();}
	
	/* PRINT VIEW */	
	function cl(i){  
   		if (i<10){  
  		   i="0"+i;  
  	 	}  
  		return i;  
	}
	
	var weekday=new Array(7);
	weekday[0]="Pazar";
	weekday[1]="Pazartesi";
	weekday[2]="Salý";
	weekday[3]="Çarþamba";
	weekday[4]="Perþembe";
	weekday[5]="Cuma";
	weekday[6]="Cumartesi"; 
	
	$(".print").bind('click',function(){
		var pathname = window.location;
		if($('.thumbnails-container').length){
			var tc = $('.thumbnails-container').html();
		}
		else { tc = ' '; }
		
		if($('.attachments-container').length){
			var ac = $('.attachments-container').html();
		}
		else { ac = ' '; }
		
		var thumbnails = '<div>'+ tc +'</div>';
		var attachments = '<div>'+ ac +'</div>';
		var myDate = new Date();
		var date =  cl(myDate.getDate())+ '.' + cl(myDate.getMonth()+1) + '.' + myDate.getFullYear() +' '+ weekday[myDate.getDay()]  + ' - '+ cl(myDate.getHours()) +':'+ cl(myDate.getMinutes()) +':'+ cl(myDate.getSeconds());
		var contact = 'Dumlupýnar Bulvarý No:252 (Eskiþehir Yolu 9.Km) 06530 /ANKARA <br/>Tel : +90(312) 218 20 00 (PBX) <br/>Faks : +90(312) 219 40 90-93 <br/> E-posta : info@tobb.org.tr';
		var winObj =  window.open('','RecipeWindow','width=685,height=600,scrollbars=yes,toolbar=yes');
		var html = '<html><head><title>TOBB ::: T&uuml;rkiye Odalar ve Borsalar Birli&#287;i</title><link href="/Style Library/style/tobb_print.css" rel="stylesheet" type="text/css" /></head><body><div class="content-container"><p align="center"><img src="/Style Library/images/tobb_logo.jpg"/></p><br/><div>' + $('#left-column').html() + '</div><br/><br/>'+ thumbnails +'<br/>'+ attachments +'<br/>'+ date +'<p class="page-url"><b>URL : </b> '+pathname+' </p><p class="page-url">'+contact+'</p></div></body></html>';
		winObj.document.open();
		winObj.document.write(html);
		winObj.document.close();
		return false;
	});	

	/* SEARCH FIX */	
	$('.srch-gosearchimg').attr('src','/Style Library/images/blank.gif');
	$('.srch-gosearchimg').removeAttr('onmouseout');	
	$('.srch-gosearchimg').removeAttr('onmouseover');

	/* LIVE FEED FIX */	
	var liveFeedInterval = 5000;
	var liveFeedContent = $('#live-feed-container div > div').html();	
	$('#live-feed-container').html(liveFeedContent);
	$('#live-feed .right > div').hide('fast');
	$('#live-feed .right > div:first').fadeIn();
	$('#live-feed .right > div:first').addClass('current');	
	function autoLiveFeed(){
		liveFeedSlide = setInterval(function(){
			$thechosenone = $('#live-feed .right > div.current');
			$thechosenone.hide();
			$thechosenone.next().fadeIn();
			$thechosenone.removeClass('current');
			$thechosenone.addClass('last-current');
			$('#live-feed .right > div.last-current').next().addClass('current');
			$('#live-feed .right > div.last-current').removeClass('last-current');
			$('#live-feed .right > div:first').insertAfter('#live-feed .right > div:last');
		}, liveFeedInterval);	
	}

	if($('#live-feed .right > div').length > 1){autoLiveFeed();}	

	/* TITLE NAV */
	$('#footer-top .navigation').each(function(){	
		var h = $(this).height();
		if(h > 211)
		{
			var p = Math.ceil(h/211);
			$(this).menuSlice(p,h,211);
		}		
	});
	

	/* MEETING NAV */
	var pI  = 1;	
	var count = $('#meeting-box .meeting-container div').size();	
	if(count > 1){		
		$('.meeting-container div:first').addClass('current');	
		$('#meeting-box .title').append('<a href="#" class="down"></a><a href="#" class="up"></a><span class="right"><span class="pI">1</span> / '+ count +'</span>');
		$('.meeting-container div:not(.current)').hide();	
	}
	
	function rotateSwitch(){		
		meetingInterval = setInterval(function(){
			meetingSlide('up');	
		},4000);
	}

	$('#meeting-box').hover(function(){clearInterval(meetingInterval);},function(){rotateSwitch();});	
	$('#meeting-box .title a').each(function(){	
		$(this).bind('click',function(){
			clearInterval(meetingInterval);
			pos = $(this).attr('class');
			meetingSlide(pos);
			return false;	
		});	
	});
	
	function meetingSlide(pos){
		if(pos == 'down')
		{
			pI--;
			if(pI <= 0) pI = count;	
			$('.meeting-container div.current').hide().removeClass('current');
			$('.meeting-container div:nth-child('+pI+')').addClass('current').fadeIn();
			$('#meeting-box .title .pI').html(pI);		
		}
		else
		{
			pI++;
			if(pI > count) pI = 1;
			$('.meeting-container div.current').hide().removeClass('current');
			$('.meeting-container div:nth-child('+pI+')').addClass('current').fadeIn();
			$('#meeting-box .title .pI').html(pI);
		}
	}
	if($('.meeting-container div').length > 1){ rotateSwitch();	}
	
	/* MEETING SEARCH */
	$('.treeview-container .sectorname').live('click',function(){
		$(this).parent().find('.meeting-container').slideToggle();
		return false;
	});
	
	/* SELECT ALL */
	$('.check-master input').bind('click',function(){
		var checked_status = this.checked;
		$(".check-cell input").each(function(){this.checked = checked_status;});
	});

	/* e-SERVICES */
	$('#e-services h3').html('<span>'+ $('#e-services h3').text() +'</span>');
	$('#e-services h3 span').bind('click',function(){
		window.location='/Sayfalar/Hizmetler.aspx';
	});
	
	if($('.pt-container').length){
		var newPageTitle = $('.pt-container input').val();		
		if(newPageTitle == ""){$('.subpage-content h3.title').html('Üye Arama');}else{$('.subpage-content h3.title').html(newPageTitle);}		
	}
	
	/* USER NAME */	
	var nameStr = $('#RibbonContainer-TabRowRight .s4-trc-container-menu a span').text().split('|');
	if(nameStr.length > 1){
		$('#RibbonContainer-TabRowRight .s4-trc-container-menu a span').text('TOBB | '+ nameStr[2] );
	}
	
	/* PAGE TOP */
	$('#left-column .box .link').bind('click',function(){
		$( 'html, body' ).animate( { scrollTop: 0 }, 0 );
	});
	
	/* SHARE */	
	$('#content-links-container a').each(function(){
		$(this).bind('click',function(){
			var u = window.location;
			var t = 'TOBB';
			var s = $(this).attr('class');
			
			if(s == "facebook"){
				window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=1,status=1,scroll=1,width=980,height=480');
				return false;
			}
			else if(s == "twitter"){
				window.open('http://www.addtoany.com/add_to/twitter?linkurl='+encodeURIComponent(u)+'&linkname='+encodeURIComponent(t),'sharer','toolbar=1,status=1,scroll=1,width=980,height=480');
				return false;
			}
		});									 
	});

	/* RIBBON CONTROL */
	$('#s4-ribbonrow #RibbonContainer').length ? $('#s4-ribbonrow').show() : $('#s4-ribbonrow').hide();
	
	
	var substrURL2 = window.location.pathname.split('/');
    	var sc2		= substrURL2.length;
	$('#header-container h1').attr('class','tr');
	for(i=0;i<=sc2-1;i++){
		if(substrURL2[i] == "Admin.aspx"){
			$('.s4-trc-container-menu').show();
		}
		else
		{
			$('.s4-trc-container-menu').hide();
		}
	}
	
	if( $('.ms-siteactionsmenu span').length > 0){$('.s4-trc-container-menu').show();}
	
	/*$('.s4-trc-container-menu').show();*/
});

$.fn.menuSlice = function(p,h, mh){
	 var menuPos 	= 0;
	 var newPos 	= 0;
	 var menuH 		= mh;
	
	 $(this).parent().parent().prev('.title').append('<a href="#" class="down"></a><a href="#" class="up"></a>');
	
	 $('.down').bind('click',function(){
	 	var currentPos = $(this).parent().next().find('.navigation').position().top;
	 	$listMenu = $(this).parent().next().find('.navigation');
	 	currentPos = currentPos - menuH;
	 	if(currentPos >= -h){
	 		$listMenu.animate({top: currentPos},500);
	 	}
	 	return false;
	 });
	
	 $('.up').bind('click',function(){
	 	var currentPos = $(this).parent().next().find('.navigation').position().top;
	 	$listMenu = $(this).parent().next().find('.navigation');
	 	currentPos = currentPos + menuH;
	 	if(currentPos <= 0){
	 		$listMenu.animate({top: currentPos},500);
	 	}
	 	return false;
	 });
};

$.fn.dropdown = function() {
	$(this).hover(function(){
		$(this).addClass("hover");
		$('> .dir',this).addClass("open");
		$('ul:first',this).css('visibility', 'visible');
		
	},function(){
		$(this).removeClass("hover");
		$('.open',this).removeClass("open");
		$('ul:first',this).css('visibility', 'hidden');
	});
};


function OpenMapDialog(itemId) 
{	
   var options = SP.UI.$create_DialogOptions();
   options.url = "/SitePages/ZiyaretGoruntuleri.aspx?rid=" + itemId.toString();
   options.width = 1000;
   options.height = 650;
   SP.UI.ModalDialog.showModalDialog(options);
}

	$.datepicker.regional['tr'] = {
		closeText: 'kapat',
		prevText: '&#x3c;geri',
		nextText: 'ileri&#x3e',
		currentText: 'bugün',
		monthNames: ['Ocak','Şubat','Mart','Nisan','Mayıs','Haziran',
		'Temmuz','Ağustos','Eylül','Ekim','Kasım','Aralık'],
		monthNamesShort: ['Oca','Şub','Mar','Nis','May','Haz',
		'Tem','Ağu','Eyl','Eki','Kas','Ara'],
		dayNames: ['Pazar','Pazartesi','Salı','Çarşamba','Perşembe','Cuma','Cumartesi'],
		dayNamesShort: ['Pz','Pt','Sa','Ça','Pe','Cu','Ct'],
		dayNamesMin: ['Pz','Pt','Sa','Ça','Pe','Cu','Ct'],
		weekHeader: 'Hf',
		dateFormat: 'dd.mm.yy',
		firstDay: 1,
		isRTL: false,
		showMonthAfterYear: false,
		yearSuffix: ''};
	$.datepicker.setDefaults($.datepicker.regional['tr']);

