/*var metin="EÅŸref ArmaÄŸan, Volvo reklam filmi... http://bit.ly/Lv2Rf http://ff.im/bbJO0";

metin.replace("http://","<a href=\"#\">http://");

alert(metin);
*/

var currenttab=2;
var order="fetured";
function golink(url){document.location.href=url;}
function opentab(num){
	if(num!=currenttab){
		
		switch(num){
			case 1 :
			tweets(0,1,null);
			window.location.href="#/pazarlama-tweetleri/";
			break;
			case 2 :
			tweets(0,7,null);
			window.location.href="#/uzman-tweetleri/";
			break;
			case 3 :
			tweets(0,3,null);
			window.location.href="#/medyanet-tweetleri/";
			break;
			case 4 :
			tweets(0,4,null);
			window.location.href="#/tum-tweetler/";
			break;
		}
		$('#tabText').css('display','block');
		$('#pagetitle_'+currenttab).fadeOut(0,function(){ $(this).css('display','none'); });
		$('#pagetitle_'+num).fadeIn(500,function(){ $(this).css('display','block'); });
		
		
		
	}
	document.getElementById('tab'+currenttab).className='tab'+currenttab;
	document.getElementById('tab'+num).className		='tab'+num+' currenttab';
	currenttab=num;
}

function closePageTitle(){
	$('#tabText').fadeOut(500,function(){ $(this).css('display','none'); });
	
}
$(document).ready(function(){
	
	
	var myurl=location.href;
	
	if(myurl.indexOf("/u/")==-1 && myurl.indexOf("/q/")==-1 &&  myurl.indexOf("/a/") == -1){
		init();
		tweets(0,7,null);
		$('#pagetitle_2').fadeIn(500,function(){ $(this).css('display','block'); });
	}else if(myurl.indexOf("/u/")!=-1){
		var myurl=myurl.substring((myurl.indexOf("/u/")+3),myurl.length);
		tweets(0,8,unescape(myurl));
		
	}else if(myurl.indexOf("/#/")!=-1){
		var myurl=myurl.substring((myurl.indexOf("/#/")+3),myurl.length);
		
		switch(myurl){
			case "pazarlama-tweetleri/" : 	opentab(1); break;
			case "uzman-tweetleri/" : 		opentab(2); break;
			case "medyanet-tweetleri/" : 	opentab(3); break;
			case "tum-tweetler/" 	:		opentab(4); break;
			
		}
		
	}else if(myurl.indexOf("/a/")!=-1){
		
	
	}else{
		
		
		var myurl=myurl.substring((myurl.indexOf("/q/")+3),myurl.length);
			tweets(0,6,decodeURI(myurl));
	}
	
	$('#sfield').keydown(function(e){
		if(e.which==13){
			var val=e.target.value;
			window.location.href="/q/"+encodeURI(val);
		}
	});
	
	$('#searchbutton').click(function(e){window.location.href="http://www.pazarlamasohbetleri.com/q/"+escape($('#sfield').val());});
});
function init(){tweets(0,7);setTimeout("refleshdb()",3000);}
function cord(or){order=or;}
function refleshdb(){
	$('#loader').fadeIn("fast");
	$.ajax({type:"GET",url:"index.php",data:"view=2",success:function(msg){}});
	$.ajax({type:"GET",url:"index.php",data:"view=3",success:function(msg){$('#loader').fadeOut("slow");}});
}
function tweets(p,poz,username,t,cat,order){
	
	if(cat!='undefined'){cat=$('#catName').val()}

	$('#loader').fadeIn("fast");
	var container=$('#center');
	$.ajax({type: "GET",url: "http://www.pazarlamasohbetleri.com/index.php",data: "view=1&p="+p+"&poz="+poz+"&username="+username+"&or="+order+"&t="+t+"&cat="+cat,
	success: function(data){
		container.html('');
		container.append(data);
		$('#loader').fadeOut("slow");
		
		
		
		
	}});
}




function search(p){
	var container=$('#center');
	closePageTitle();
	//$('.currenttab').css('background-position','top');

	$('.tabText').fadeOut(500,function(){ $(this).css('display','none'); });
	
	
	//window.location.href="http://188.132.208.10/~pazar/?view=search&query="+escape($('#sfield').val());
	//alert("a");
	$.ajax({type: "GET",url: "http://www.pazarlamasohbetleri.com/index.php",data: "view=search&p="+p+"&text="+escape($('#sfield').val()),
	success: function(data){
		container.html('');
		container.append(data);
		$('#loader').fadeOut("slow");
	}});
}

function emailR(email){
	var box=$('#euyari');
	box.css('display','block');
	
	
	//$('.currenttab').css('background-position','top');

	//$('.tabText').fadeOut(500,function(){ $(this).css('display','none'); });
	
	
	//window.location.href="http://188.132.208.10/~pazar/?view=search&query="+escape($('#sfield').val());
	//alert("a");
	$.ajax({type: "GET",url: "index.php",data: "view=emailR&email="+$('#efield').val(),
	success: function(data){
		
		box.html('');
		box.append(data);
		window.setTimeout(function() {
			box.fadeOut(1500,function(){ $(this).css('display','none'); });
		}, 1800);
	}});
}

function oyver(id,vote){
	var container=$('#oyver_'+id);
	var votee = vote+1;
	container.fadeOut("fast");
	$.ajax({type:"GET",url:"http://www.pazarlamasohbetleri.com/index.php",data:"view=4&id="+id,success:function(msg){
		if(msg!="error"){
			container.html(' <div id="oy_'+id+'" class="oy">'+votee+' <br><span>OY </span></div>');
			container.append('<span class="OYver">VERDİN</span>');
			container.fadeIn("slow");
		}else{
			container.fadeIn("slow");
		}
	}});
}
var openreply;
function replyver(id,un){
	if(openreply==null){
		openreply=id;
	}else{
		var container=$('#reply_'+openreply);
		container.animate({height: "0px"},700);
		container.html("");
		if(openreply==id){openreply=null; return false;}
		openreply=id;
	}
	var container=$('#reply_'+id);
	container.animate({height: "130px"},700);
	$.ajax({type:"GET",url:"http://www.pazarlamasohbetleri.com/index.php",data:"view=5&username="+un+"&id="+id,success:function(msg){container.html(msg);}});
}
function replyat(id){
	var container=$('#reply_'+id);
	var un=$("#username").val();
	var up=$("#password").val();
	var msg=$("#messages").val();
	var hatirla=($("#twitter_remember").val()=="on")?1:0;
	//if(un==""){
	//	$("#username_error").html("LÃ¼tfen KullanÄ±cÄ± AdÄ±nÄ±zÄ± Girin");
	//	$("#username_error").addClass("errordiv");
	//	container.animate({height: "260px"},400);
	//	return false;
	//}
	//if(up==""){
	//	$("#password_error").html("LÃ¼tfen Å�ifrenizi Girin");
	//	$("#password_error").addClass("errordiv");
	//	container.animate({height: "300px"},400);
	//	return false;
	//}
	$.ajax({type:"GET",url:"index.php",data:"view=6&username="+un+"&password="+up+"&message="+msg+"&id="+id,success:function(msg){container.html(msg);}});
}
function getuser(id,container){
	var container=$('#'+container);
	container.html("<br><br>");
	container.css("background","url('images/ajax-loader.gif') no-repeat");
	container.css("background-position","30px 10px");
	$.ajax({type:"GET",url:"action.php",data:"a=7&id="+id,success:function(msg){
		container.css("background","none");
		container.html(msg);
	}});
}
function submitform(target)
{
    document.forms[target].submit();
}
function submitMail(send){

	$.ajax({type:"GET",url:"index.php?view=sendMail&",data: $('formMail').serialize(),success:function(msg){
		container.css("background","none");
		$('sonuc').html(msg);
	}});
}
var currentpage=0;
function toppost(way){
	/*var container=$('#toppostcontainer');
	container.fadeOut("fast");
	$.ajax({type:"GET",url:"action.php",data:"a=8",success:function(msg){
		container.html(msg);
		container.fadeIn("fast");
	}});*/
}
function callculatecharcter(){
	var val=$('#messages').val();
	val=140-val.length;
	if(0<=val){
		$('#maxchr').html(val);	
	}else{
		var currenttext=$('#messages').val();
		$('#messages').val(currenttext.substring(0,140));
		$('#maxchr').html("0");	
	}
	
}



function changeColor(id){
	$('#tweet_'+id).css("background-color","#eeeeee");	
}
function changeColorOut(id){
	$('#tweet_'+id).css("background-color","#ffffff");	
}

function changestyle(a,b){
	$('#'+a).css("font-weight","bold","text-decoration","underline");
	$('#'+b).css("font-weight","normal");
	
}

function KlightBox(divID){
    
    var documentHeight=jQuery(document).height();
    var windowHeight=jQuery(window).height();
    var documentWidth	=jQuery(document).width();
    var windowWidth	=jQuery(window).width();
    var boxWidth	=600;
    var boxHeight=400;
    var boxTop=(windowHeight - boxHeight)/2;
    var boxLeft=(windowWidth-boxWidth)/2;    
    var sct=jQuery(window).scrollTop();
    var image=jQuery("#"+divID).attr("rel");			
    jQuery("body").append("<div class='KlightBox-overlay' onclick='KlightBoxClose()'></div><div class='KlightBox-lightbox' onclick='KlightBoxClose()'></div>");    
    jQuery(".KlightBox-overlay").css("height",documentHeight).show();
    jQuery(".KlightBox-lightbox").css("top",boxTop).css("left",boxLeft).html("<div width=620 height=420 style='margin-top:10px;' ><image style='float:right;margin-right:10px;' src='http://www.pazarlamasohbetleri.com/images/kpat.jpg'><iframe frameborder=0 scrolling=no width=550px height=320px border=0 src='"+image+"'></iframe></div>").fadeIn("slow");
}

function KlightBoxClose(){
  
  jQuery(".KlightBox-overlay").hide();
  jQuery(".KlightBox-lightbox").fadeOut("slow");
}