$(document).ready(function(){

	var site_url ='http://picpickle.com/';
	$("#s").autocomplete(suggest); // oto tanımlama
	$('a[rel*=modalbox]').facebox(); // modalboxlar

	
	$('#search_form').submit(function(){
		var search = $('#search_text_id').val();

		switch ( search ){
			case '1' : search_url = 'p.php?s='+$('#s').val(); break;
			case '2' : search_url = 'videos.php?s='+$('#s').val(); break;
			case '3' : search_url = 'a.php?s='+$('#s').val(); break;
			case '5' : search_url = 'people.php?fprofile=1&s='+$('#s').val(); break;
			case '6' : search_url = 'photos.php?s='+$('#s').val(); break;
		}

		window.location = site_url+search_url;
		return false;
	});
	
	/* sol ve sağ blokların yüksekliklerini eşitle */
	if ( homepage ) {
		var rbmid_height = $('.rbmid').height();
			sidebar_height = $('.sidebar').height();
		if ( rbmid_height < sidebar_height ) $('.rbmid').height($('.sidebar').height()-25);
	}
	/* sol ve sağ blokların yüksekliklerini eşitle */

	/* sağ blok thumbnaillerin üzerine gelince efekt uygula */
	$('.imageGallery .thumbs img').hover(function(){
		$(this).fadeTo('fast',1);
	},function(){
		if ( $(this).attr('class') == 'active' ) { return false; }
		$(this).fadeTo('fast',0.5);
	}
	);
	/* sağ blok thumbnaillerin üzerine gelince efekt uygula */
	
	/* video resimlerinin üzerine gelince efekt uygula */
	$('.videos .thumb').hover(function(){
		$(this).find('.video_play').show();
	},function(){
		$(this).find('.video_play').hide();
	}
	);
	/* video resimlerinin üzerine gelince efekt uygula */
	

	/* thumbnaillerin üzerine tıklayınca resmin büyük halini sol tarafta göster */
	$('.imageGallery .thumbs img').click(function(){
		$('.imageGallery .thumbs img').fadeTo(0,0.5);
		if ( $(this).attr('class') =='active' ) { $(this).fadeTo('fast',1); return false; }
		$('.imageGallery .image img').hide();
		nextPic = $(this).attr('src').replace('_thumb','');
		$('.imageGallery .thumbs img').removeClass('active');
		$(this).addClass('active');
		$('.imageGallery .image img').attr('src',nextPic);
		$('.imageGallery .image img').fadeIn(750);
		$('.imageGallery .image img').width(500);
		$('.imageGallery .image img').height(275);
		$(this).fadeTo('fast',1);
	});
	/* thumbnaillerin üzerine tıklayınca resmin büyük halini sol tarafta göster */
	
	/* sol menü alışveriş bölümüğ sol ve sağ okları */
	var i_limit = 3;
		i_current =1;
	$('.shoppingL').click(function(){
		if ( i_current > 1 ) {
			i_current = i_current - 1;
			$('#i'+parseInt(i_current+1)).fadeOut('fast');
			$('#i'+i_current).fadeIn('fast');
			$('#d'+parseInt(i_current+1)).hide();
			$('#d'+i_current).show();
		}
	});
	
	$('.shoppingR').click(function(){
		if ( i_current < i_limit ){
			i_current++;
			$('#i'+parseInt(i_current-1)).fadeOut('fast');
			$('#i'+i_current).fadeIn('fast');
			$('#d'+parseInt(i_current-1)).hide();
			$('#d'+i_current).show();
		}
	});
	/* sol menü alışveriş bölümüğ sol ve sağ okları */


	/* makale tablarının değişimi */
	$('.articles_tab ul li a').click(function(){
		$('.article_tab_divs').hide();
		$('#tab'+$(this).attr('rel')).show();
	});
	/* makale tablarının değişimi */
	
	

});

/* arama kutusu açılır kutu */
var hide= false;
function show_searchSelect(){
	if(!hide) document.getElementById("search_list").style.visibility="visible";
	hide= false;
}
function setText(val,id){
	hide=true;
	hide_list();
	document.getElementById("search_text").value=val;
	document.getElementById("search_text_id").value=id;
}
function hide_list(){
	document.getElementById("search_list").style.visibility="hidden";
}
/* arama kutusu açılır kutu */

/* dil değiştir */
function change_lang(lang){
   	$("#change_lang_form [name=change_lang_form_lang]").val(lang);
   	$("#change_lang_form").submit();
}

/* sol menü tüm kategorileri göster - gizle*/
function show_all_cats(){
	$('.show_all_cats').toggle();
	$('#all_cats').toggle();
}
/* sol menü tüm kategorileri göster - gizle*/



function checkUpload(){

		if ( $("#uploadType1:checked").val() == "1" && $("#imgfile").val() == "") {
		
			alert("Yüklenecek resim seçmediniz");
			return false;

		}

		if ( $("#uploadType1:checked").val() == "1" && $("#imgfile").val() != "") {
		
			var ext = /[^.]+$/.exec( $("#imgfile").val() ).toLowerCase();
			if ( ext != "jpg" && ext != "jpeg" && ext != "png" && ext != "gif" ) { alert("Bu format desteklenmiyor"); return false; }  

		}


		if ( $("#uploadType2:checked").val() == "2" && $("#imgurl").val() == ""  ) {
		
			alert("URL girmediniz");
			return false;
		
		}

		if ( $("#uploadType2:checked").val() == "2" && $("#imgurl").val() != "" ) {

			var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
			if ( regexp.test( $("#imgurl").val() ) ) {
			
				var ext = /[^.]+$/.exec( $("#imgurl").val() ).toLowerCase();

				if ( ext != "jpg" && ext != "jpeg" && ext != "png" && ext != "gif" ) { alert("Bu format desteklenmiyor"); return false; }  
				
			} else {
			
				alert("Geçersiz bir URL girdiniz");
				return false;
				
			}
			
		}		
		

		return true;
	
}
