function share(name, description, msg, image) {
	FB.ensureInit(function(){
		
		var href 		= 'http://www.competus.com.tr';
		var actionlinks	= [{"text":"Hikayeni Paylaş","href":"http://www.competus.com.tr/"}];
		
		var attachment = {
		'name':'Competus\'la macera dolu bir keşfe çıkıyoruz!',
		'href':href,
		'caption':href,
		'description': 'Competus Keşif Konvoyu doğa ve macera tutkunlarını buluşturuyor. Sen de ister kendi maceranla katıl; ister maceraları oku, oy ver, bu eşsiz keşif gezisine kimlerin katılacağını belirle!',
		'media': [{'type':'image',
		'src':'http://www.competus.com.tr/_img/facebook_share_icon.jpg',
		'href':href}]};
		
		FB.Connect.streamPublish(msg, attachment, actionlinks);
	});
}

$(function(){
	

	
	//$('a.kazananinfo').click(function(){  $('#lightbox').fadeIn(300);})
	$('a.kesifDetayLink').click(function(){
				hikayeId = $(this).attr('rel');
				$('#lightbox').append("<img class='loadingCon' src='_img/ajax-loader.gif' width='56' height='21' />");
				$('#lightbox').load('/index.php/kesifhikayeleri/detail/'+hikayeId+'/kazanan');
			})
			
	jQuery.each(jQuery.browser, function(i, val) {
		if(i=="msie" && jQuery.browser.version.substr(0,3))
			$('img#logobg').attr({src: 'http://www.competus.com.tr/_img/logo.gif'})
			$('img#kertenkele').attr({src: 'http://www.competus.com.tr/_img/kertenkele.gif'})
	});
	
	$('#userLoginClosed').click(function(){	$(this).animate({top : -45}, function(){$(this).next().load('/index.php/uyeler/logincontrol/'+Math.random(), initLinks); $(this).next().show().animate({top : 0});}); 
	})
	//intro();
	$('.close').click(function(){$(this).parent('div').fadeOut(100)})
	/*$('#logoMasked').bind("mouseenter", function(){
		if($('img#bannerImg').queue("fx").length<1)
		{
			$('img#bannerImg').animate({left: '-202px'})
		}
	}).bind("mouseleave", function(){ 
		$('img#bannerImg').animate({left: '0'})
	})*/
	
	$('#navAnasayfa').click(function(){
		introRemove();
		overlay('/index.php/konvoy')
	})
	
	$('#navGecenSeneler').click(function(){
		introRemove();
		$('input#year').val('2007');
		overlay('/index.php/gecenseneler/index/2007/on')
	})
	$('#navKesifHikayeleri').click(function(){
		introRemove();
		overlay('/index.php/kesifhikayeleri/index/oyalanlar/1/first')
	})
	
	
	
	$('a#katilimKosullari').click(function(){ introRemove(); overlay('/index.php/kesifhikayeleri/katilimsartlari')})
	
	//Pure Logo
	/*var fo = new SWFObject("/_swf/pure-logo.swf", "pureLogo", "17", "57", "8", "#FFFFFF");
	fo.addParam("wmode", "transparent");
	fo.addParam("menu", "false");
	fo.write("pure");*/
})

function closeLoginAreas(){
	$('#userLogin').animate({top : -45}).hide();
	$('#userLoginInfo').animate({top : -45}).hide();
	$('#userLoginClosed').animate({top : 0});
}

function intro(){ 
	$('#container').append("<div id='intro'><img id='logoSub' src='_img/logo-sub.png' width='305' height='313' alt='' /><img src='_img/intro.jpg' title='Keşifler Seni Bekliyor!' usemap='#Map' /><a class='close' onclick='introRemove();' href='javascript:;' title='kapat'>Kapat</a></div>"); 		
	jQuery.each(jQuery.browser, function(i, val) {
		if(i=="msie" && jQuery.browser.version.substr(0,3))
			$('img#logoSub').attr({src: 'http://www.competus.com.tr/_img/logo-sub.gif'})
	});}

function introRemove(){
	$('#intro').fadeOut(100).remove();
	$('img#bannerImg').animate({left: '0'})
}

function endRemove(){
	$('#end').fadeOut(100).remove();
	$('img#bannerImg').animate({left: '0'})
}

function initLinks(){
	$('#tabsGecen a').unbind('click');
	$('#tabsKesif a').unbind('click');
	$('ul.2010KonvoyLMenu li a').unbind('click');
	
	jQuery.each(jQuery.browser, function(i, val) {
		if(i=="msie" && jQuery.browser.version.substr(0,3))
			$('img#logoSub').attr({src: 'http://www.competus.com.tr/_img/logo-sub.gif'})
	});
	
	//hikaye gonder loading
	function setContentLoading(b)
	{
		if (b == 1)
		{
			$('#lightbox').prepend(
				$('<div id="contentOverlay" />')
				.css({ width:'100%', height:'533px', backgroundColor:'#000', opacity:'0.6', position:'absolute', top:0, left:0, zIndex:'150' })
				.append("<img class='loadingCon' src='_img/ajax-loader.gif' width='56' height='21' />")
			)	
		}
		else { $('#contentOverlay').remove(); }
	}
	
	$('#logo').pngFix();
	 $('img#kertenkele').pngFix();
	 $('#lightbox img#logoSub').pngFix();
	
	$('#userLogin input').focus(function(){$(this).val("")})
	
	$('a.forgetPassword').click(function(){
		$('#userLogin').html('<p class="fps">Şifremi Unuttum</p><input type="text" value="Email adresi" id="fpEmail"><a title="Gönder" href="javascript:;" id="fplogin">Login</a><div id="userLoginBottom">Giriş yapmak için <a href="javascript:;" id="fpsGeri">geri dön.</a></div>');
		initLinks();
	})
	
	$('#fpsGeri').click(function(){
		$('#userLogin').load('/index.php/uyeler/logincontrol/'+Math.random(), initLinks);							 
	})
	
	$('a#fplogin').click(function(){
		mail = $('#fpEmail').val();
		$.post("/index.php/sifremiunuttum/index", { mail: mail }, function(data){
			 switch (data) {
				 case "1":
				 alert('Şifreniz E-mail adresinize gönderildi.');
				 $('#userLogin').load('/index.php/uyeler/logincontrol/'+Math.random(), initLinks);
				 break;
				 
				 case "2":
				 alert('Mail Adresi Boş');
				 break;
				 
				 case "3":
				 alert(' Bu mail adresiyle kayıt yok.');
				 break;
			 }
		});							  
	});
				
	
	//Uye girisi
	$('#login').click(function(){
		mail = $('#userLogin input#uLEmail').val();
		pass = $('#userLogin input#uLPass').val();
		$.post("/index.php/uyeler/login", { mail: mail, password:pass }, function(data){
			 switch (data) {
				 case "1":
				 $('#userLogin').load('/index.php/uyeler/logincontrol/'+Math.random(), initLinks);
				 break;
				 
				 case "2":
				 alert('Mail veya Şifre Boş.');
				 break;
				 
				 case "3":
				 alert('Bilgiler Yanlış');
				 break;
				 
				 case "4":
				 alert('Teknik Sorun.');
				 break;
			 }
		});
	})
	
	//uyelik islemleri
	
	$('.close').click(function(){$(this).parent('div').fadeOut(100); $('#overlay').fadeOut(200, function(){ $(this).remove() })})
	//Sol menuye tiklandiginda hidden dan yili al. click olayından idyi al ve sonuca gore loadi gerceklestir.
	$('ul.gecenLMenu li a').click(function(){
		$(this).parent('li').siblings('li').removeClass('on');
		$(this).parent().addClass('on');
	})
	
	//2010 konvoyu sol menu
	$('ul.2010KonvoyLMenu li a').bind('click', function(){
		if ($(this).parent().attr('class') != "on"){
			$(this).parent('li').siblings('li').removeClass('on');
			$(this).parent().addClass('on');
			page = $(this).attr('id');
			$('#content').append("<img class='loading' src='_img/ajax-loader.gif' width='56' height='21' />");
			$('#content').load('/index.php/konvoy/index/'+page, initLinks);
		}
	})
	
	//yil tablarina tikladiginda classlari degistir ve hangi yila tiklandiysa onun ilk sayfasini load et
	$('#tabsGecen a').bind('click', function(){
		if ($(this).attr('class') != "on"){
			$(this).siblings('a').removeClass('on');
			$(this).addClass('on');
			yil = $(this).attr('id').substr(1,4);
			$('input#year').val(yil);
			$('ul.gecenLMenu li').show();
			if(yil == '2006'){
				$('ul.gecenLMenu li a#rota2').parent('li').hide();
				$('ul.gecenLMenu li a#videogaleri').parent('li').hide();
			}
			if(yil == '2005'){
				$('ul.gecenLMenu li a#videogaleri').parent('li').hide();
			}
			$('#content').append("<img class='loading' src='_img/ajax-loader.gif' width='56' height='21' />");
			$('#content').load('/index.php/gecenseneler/index/'+yil, initLinks);
		}
	})
	
	$('#tabsKesif a').bind('click', function(){
		if ($(this).attr('class') != "on"){
			$(this).siblings('a').removeClass('on');
			$(this).addClass('on');
			hikayes = $(this).attr('id');
			hikayess = hikayes + "/1";
			
			hikayel = "/index.php/kesifhikayeleri/index/"+hikayess;
			$('#content').append("<img class='loading' src='_img/ajax-loader.gif' width='56' height='21' />");
			$('#content').load(hikayel, initLinks);
			$('input#hinput').val(hikayes);
		}
	})
	
	
	//kesif detayini yukle
	$('a.kesifDetayLink').click(function(){
		hikayeId = $(this).attr('rel');
		$('#lightbox').append("<img class='loadingCon' src='_img/ajax-loader.gif' width='56' height='21' />");
		$('#lightbox').load('/index.php/kesifhikayeleri/detail/'+hikayeId, initLinks);
	})
	
	//kesif hikayeleri sayfalama
	$('div.kesifHikayeleri div.paging span a').click(function(){
		if ($(this).attr('class') == "on"){ return;}
		else {
			$('.kesifHikayeleri').append("<img class='loading' src='_img/ajax-loader.gif' width='56' height='21' />");
			hikayes = $('input#hinput').attr('value');
			$('div.kesifHikayeleri').load('/index.php/kesifhikayeleri/index/'+hikayes+'/'+$(this).attr('rel'), initLinks);
		}
	})
	
	//uye ol post
	$('a#uyeOlBtn').click(function(){
		ad = $('#ad').val();
		soyad = $('#soyad').val();
		dGun = $('#dGun').val();
		dAy = $('#dAy').val();
		dYil = $('#dYil').val();
		cinsiyet = $('#cinsiyet').val();
		cepNo = $('#cepNo').val();
		adres = $('#adres').val();
		sehir = $('#sehir').val();
		emailAdresi = $('#emailAdresi').val();
		sifre = $('#sifre').val();
		sifreTekrar = $('#sifreTekrar').val();
		ehliyetYili = $('#ehliyetYili').val();
		kanGrubu = $('#kanGrubu').val();
		meslek = $('#meslek').val();
		egitimDurumu = $('#egitimDurumu').val();
		cepCar = cepNo.length;
		if (cepCar < 11) { alert("Telefon numaranız en az 11 kararter olmalıdır."); return; }
		if(sifre == sifreTekrar) { 
			$.post("/index.php/uyeler/kayit", { first_name: ad, last_name: soyad, dGun: dGun, dAy: dAy, dYil: dYil, sex: cinsiyet, gsm: cepNo, county: sehir, adress: adres, driver_license_date: ehliyetYili, blood_group: kanGrubu, job: meslek, educational_status: egitimDurumu, mail: emailAdresi, password: sifre }, function(data){
				 switch (data) {
					 case "1":
					 $('#content').html('<br /><p>Üyelik işleminiz başarıyla tamamlanmıştır. Keşif Hikayenizi paylaşmak için lütfen ‘Üye Girişi’ yapınız.</p>');
					 break;
					 
					 case "2":
					 alert('Lütffen zorunlu alanları doldurunuz');
					 break;
					 
					 case "3":
					 alert('Girdiğiniz mail adresi kullanımda.');
					 break;
					 
					 case "4":
					 alert('Teknik Sorun.');
					 break;
				 }
			});
		}
		else {alert("Girdiğiniz şifreler aynı değil");}
	})
	
	
	//yeni hikaye post
	$('a#gonderBtn').click(function(){
		if ( $('#formType').val() == '1' )
		{
			cepNo = $('#cepNo').val();
			cepCar = cepNo.length;
			if (cepCar < 11) { alert("Telefon numaranız en az 11 kararter olmalıdır."); return; }
		}
		
		setContentLoading(1)
		var options = {
			url: '/index.php/kesifhikayeleri/kayit',
			type: 'POST',
			iframe: true,
			success: function(e){
				setContentLoading(0)
				switch (e) {
					case '1':
						$('#content').html('<p>Hikayeniz kontrol edildikten sonra yayına alınacak ve size bilgilendirme maili gönderilecektir.</p>');
					break;
					case '2':
						alert('Sadece Üyeler hikaye gönderebilir.')
					break;
					case '3':
						alert('Sadece 1 tane hikaye gönderebilirsiniz.')
					break;
					case '4':
						alert('Lütfen tüm alanları doldurunuz.')
					break;
					case '5':
						alert("Fotoğrafın .jpg, .png ya da .gif formatında olmalı.")
					break;
					case '6':
						alert("Teknik bir sorun oluştu.")
					break;
				}
			}
		}
		
		$('#content form').ajaxSubmit(options)
		//}
	})
	
	$('a#devamBtn').click(function(){ $('div#form').animate({top: '-400px'}); $('#up').show(); })
	
	$('a#up').click(function(){ $('div#form').animate({top: '0'}); $('#up').hide();})
	
	//yeni hikaye formunu ac
	$('ul#leftMenu a#hikayeyaz').click(function(){
		$('#lightbox').append("<img class='loadingCon' src='_img/ajax-loader.gif' width='56' height='21' />");
		$('#lightbox').load('/index.php/kesifhikayeleri/form', initLinks);
	})
	
	$('#showAll').click(function(){
		$('#content').append("<img class='loading' src='_img/ajax-loader.gif' width='56' height='21' />");
		$('#content').load('/index.php/kesifhikayeleri/index/hepsi', initLinks)							 
	})
	
	$('a.basvur').click(function(){
		$('#lightbox').append("<img class='loading' src='_img/ajax-loader.gif' width='56' height='21' />");
		$('#lightbox').load('/index.php/kesifhikayeleri/form/'+Math.random(), initLinks)
	})
	
	$('a.back').click(function(){
		$('#lightbox').append("<img class='loading' src='_img/ajax-loader.gif' width='56' height='21' />");
		$('#lightbox').load('/index.php/kesifhikayeleri/index/oyalanlar/1/first', initLinks)
	})
	
	//scrollpane uygula
	$('#pane3').jScrollPane();
}
/* /initlinks */

//lightboxOpen
function overlay(page, onStop, onStart){
	closeLoginAreas();
	
	var viewportHeight = $('body').height()
	var viewportWidth = $('body').width()
	var containerWidth = 838
	var containerHeight = 533
	var viewCenterPointX = (viewportWidth / 2) - (containerWidth / 2); 
	var viewCenterPointY = (viewportHeight / 2) - (containerHeight / 2);

	$('body').prepend(
		$('<div id="overlay" />')
			.css({ width:'100%', height:viewportHeight+'px', position:'absolute', top:0, left:0, zIndex:'86' })
			.append(
				$('<div id="overlayFade" />')
				.css({ width:'100%', height:viewportHeight+'px', backgroundColor:'#000', opacity:'0.6', position:'absolute', zIndex:'1' })
			)
			.append(
				$('<div id="lightbox" />')
				.css({ position:'absolute', top: 52+'px', left:viewCenterPointX+'px', zIndex:'2' })
			)
	)
	$('#lightbox').append("<img class='loadingCon' src='_img/loader.gif' width='56' height='21' />");
	$('#lightbox').load(page, initLinks);
}

function oyla(id){
	 $.post("/index.php/kesifhikayeleri/oy", { id: id }, function(data){
	 
		 switch (data) {
			 case "1":
			 
			 var vote = parseInt($('span#vote').text());
			 vote++;
			 $('span#vote').text(vote);
			 break;
			 case "2":
			 alert('Id Boş.');
			 break;
			 case "3":
			 alert('Oy Kullanmak için giriş yapmalısınız.');
			 break;
			 case "4":
			 alert('Bu Idye ait kayıt yok.');
			 break;
			 case "5":
			 alert('Daha Önce Oy Kullanmışsınız.');
			 break;
			 case "6":
			 alert('Teknik Bir Sorun Meydana Geldi.');
			 break;
		 }
	 });
}

//userInfo MacerayaKatil linki
function macerayaKatil(){
	overlay('/index.php/kesifhikayeleri/form/'+Math.random())
}

function logout(){
		$.post("/index.php/uyeler/logout/"+Math.random(), {});
		closeLoginAreas();
		$('#userLogin').load('/index.php/uyeler/logincontrol/'+Math.random(), initLinks);
	}
	
function uyeOl(){
		introRemove();
		overlay('/index.php/uyeler/uyeol/'+Math.random());
	}
	
function fbLoginnn(){
		$('#userLogin').load('/index.php/uyeler/logincontrol/'+Math.random(), initLinks);
	}
	
function fbLoginnn2(){
		$('#userLogin').load('/index.php/uyeler/logincontrol/'+Math.random(), initLinks);
		$('#lightbox').load('/index.php/kesifhikayeleri/form/'+Math.random(), initLinks)
	}

function fbLogout(){
	$('#userLogin').load('/index.php/uyeler/logincontrol/'+Math.random(), initLinks);
}


