﻿var uploadMultipleBox = $(".Upload_Multiple").height();
	$(document).ready(function(){
		$('form.upform').submit(function() {
			$(".file").animate({"height": "toggle", "opacity": "toggle"}, "slow");
			$(".upload_op").animate({"height": "toggle", "opacity": "toggle"}, "slow");
			$(".Upload_Multiple").animate({"height": 0, "opacity": 0}, "slow");
			$("#uploadbutton").animate({"height": 0, "opacity": 0}, "slow");
			$(".loading").fadeIn("slow");
		});
	});
	var count = 0;
	$(document).ready(function(){
		$('.add_another_file_input').click(function(){
			var html = $('.Upload_Multiple').prev('.input').html();
			$('.file:last').after( '<div class="input file hide">'+html+'</div>' );
			$('.file:last').animate({"height": "toggle", "opacity": "toggle"}, "slow",function(){
				$(this).children('.closeUpload').fadeIn('slow');
				$('.pref_title:last').next('.preferences').children('input#private').attr('name', 'private[' + count + ']');
				$('.pref_title:last').next('.preferences').children('input#shorturl').attr('name', 'shorturl[' + count  + ']');
			});
			count++;
			if(count >= (max-1)) $('.Upload_Multiple').animate({"height": 0, "opacity": 0}, "slow",function(){$(this).css("display", "none")});
			if(count === 2) copyfileName();
		return false;
		});
	});
	$(".closeUpload").live('click',function(){
		$(this).parent().fadeTo(400, 0, function () {
			$(this).slideUp(400,function() {
				max++;
				$('.Upload_Multiple').delay(1).css("display", "block").animate({"height": uploadMultipleBox+"px", "opacity": "100"}, "slow");
				$(this).remove();
			});
		});
		return false;
	});
	$(document).ready(function(){
		$("#linkremote").click(function(){
			$('#local_panel').fadeOut(1, function(){$('#remote_panel').fadeIn('slow');});
			$('div.hide').fadeTo(400, 0, function(){$('div.hide').slideUp(400,function(){$('div.hide').remove();});});
			$('.Upload_Multiple').animate({"height": 0, "opacity": 0}, "slow",function(){$(this).css("display", "none")});
			$('#linklocal').removeClass('linklocal show').addClass('linklocal');
			$('#file').val("");
			$('#fileName').val("");
			$('#linkremote').removeClass('linkremote').addClass('linkremote show');
			count = 1;
		});
		$("#linklocal").click(function(){
			$('#remote_panel').fadeOut(1, function(){$('#local_panel').fadeIn('slow');});
			$('.Upload_Multiple').delay(1).css("display", "block").animate({"height": '20px', "opacity": "100"}, "slow");
			$('#linklocal').removeClass('linklocal').addClass('linklocal show');
			$('#imgUrl').val("");
			$('#linkremote').removeClass('linkremote show').addClass('linkremote');
		});
	});
	$(document).ready(function(){
		$(".pref_title").live('click',function(){
			$(this).next('.preferences').animate({"height": "toggle", "opacity": "toggle"}, "slow");//slideToggle("slow");
			$(this).toggleClass("open_pref");
		});
	});
function  copyfileName() {
		var name;
		var file = document.upload.elements["file[]"];
		var file_name = document.upload.elements["fileName[]"];
		var alt = document.upload.elements["alt[]"];
		if (file.length > 0){
			for (i = 0; (i < file.length); i++) {
				if (file_name[i].value != file[i].value){
					file_name[i].value = file[i].value;
					name = file_name[i].value.slice(file_name[i].value.lastIndexOf("\\")+1,file_name[i].value.lastIndexOf('.'));
					alt[i].value = name.replace(/_|-/g," ");
				}
			}
		}else{
			file_name.value = file.value;
			name = file_name.value.slice(file_name.value.lastIndexOf("\\")+1,file_name.value.lastIndexOf('.'));
			alt.value = name.replace(/_|-/g," ");
		}
	}
	function fileExt(extArray) {
	var file = document.upload.elements["fileName[]"];
		var fileUrl = document.upload.elements["imgUrl"];
		var upCount = file.length;
		if (upCount == null) upCount = 1;
		for (i = 0; (i < upCount); i++) {
			var extOk = false;
			if (upCount == 1 && i == 0){
				if (!file.value && !fileUrl.value){
					return false;
				}else if(file.value) {
					fileItem = file;
				}else if(fileUrl.value) {
					fileItem = fileUrl;
				}
			}else if(!file[i].value){
				return false;
			}
			var filename = fileItem.value.slice(fileItem.value.indexOf("\\") + 1);
			var ext = filename.substring(filename.lastIndexOf(".")+1).toLowerCase();
			for (var i = 0; i < extArray.length; i++) {
				if (extArray[i] === ext) {
					extOk = true;
				}
			}
			if (extOk != true) {
				alert( alertfile );
				return false;
			}
		}
		return true;
	}
	function doconfirm(message,id,page) {
		if (confirm(message)) {
			var dataString = 'report='+id;
			$.ajax({
				type: "POST",
				url: "../cfajax.php",
				data: dataString,
				dataType: 'json',
				cache: false,
				success: function(result){
					$("#msg").html(result['suc']).slideDown(400).fadeTo(400, 100);
				},
				error: function(errorThrown){
					$("#msg").html(errorThrown['error']);
				}
			});
		}
		else {
			return false;
		}
	}
	$(document).ready(function(){
		var thisImg;
		$("li").hover(function(e){
			thisImg  = $(this);
			var thisImgWidth =(180-$(this).children("a.thumb").children("img").width())/2-5;
			var thisImgoffset =$(this).children("a.thumb").children("img").offset();
			var thisLiOffset =$(this).offset();
			var thisimgtop = thisImgoffset.top - thisLiOffset.top;
			$(this).children(".img_report")
				.css("right",thisImgWidth+"px")
				.css("top",thisimgtop+"px")
				.fadeIn("slow");
		},
		function(){
			$(thisImg).children(".img_report").css("display", "none");
		});
	});
	$(".close").live('click',function(){
		$(this).parent().fadeTo(400, 0, function () { // Links with the class "close" will close parent
			$(this).slideUp(400,function() {$(this).remove();});
		});
		$("#msg").slideUp().fadeTo(400, 0);// image remove fix
		return false;
	});
	$(document).ready(function() {
		$("a[name^='faq-']").each(function() {
			$(this).click(function() {
				if( $("#" + this.name).is(':hidden') ) {
					$("#" + this.name).slideDown(400).fadeTo(400, 100);
				} else {
					$("#" + this.name).fadeTo(400, 0).slideUp(400);
				}
				return false;
			});
		});
	});
	$(function() {
		$('a.tips').tipsy({fade: true, gravity: 'w'});
		$('.orderby a').tipsy({fade: true, gravity: 's'});
		$('.pagination a').tipsy({fade: true, gravity: 's'});
		$('.captcha').tipsy({fade: true, gravity: 's'});
		$('.addthis a').tipsy({fade: true, gravity: 's'});
	})
	$(document).ready(function(){
		var working = false;
		$('#addCommentForm').submit(function(e){
			e.preventDefault();
			if(working) return false;
			working = true;
			$('#submit').val('Working..');
			$('span.error').remove();
			$.post('../cfajax.php',$(this).serialize(),function(msg){
				working = false;
				$('#submit').val('Submit');
				if(msg.status){
					$(msg.html).hide().appendTo('ul#commentslist').slideDown();
					$('#body').val('');
					$('#captcha').val('');
				}else{
					$.each(msg.errors,function(k,v){
						$('label[for='+k+']').append('<span class="error">'+v+'</span>');
					});
				}
			},'json');
			$("#captchaImg").attr("src", "../img/captcha.img.php?img&amp;"+ Math.random());
		});
	});
	$(function() {
		$(".vote").click(function(){
			var id = $(this).attr("id");
			var type = $(this).attr("ref");
			var dataString = 'votes=1&id='+id+'&type='+type;
			$.ajax({
				type: "POST",
				url: "../cfajax.php",
				data: dataString,
				dataType: 'json',
				cache: false,
				success: function(result){
					$('.ratingCounter').fadeTo(400,0,function(){
						$('.ratingCounter').html(result['totle']);
						$('.ratingCounter').fadeTo(0,400);
					});
				},
				error: function(errorThrown) {
				}
			});
			return false;
		});
	});
function CreateBookmarkLink(){
var title = "ResimUP.Net - Ücretsiz Görüntü Yükleme Hizmeti";
var url  = "http://www.resimup.net";
if (window.sidebar) { 
window.sidebar.addPanel(title, url, '');
}else if (window.external)
{
window.external.AddFavorite(url, title);
}else if (window.opera && window.print)
{
return true; 
}}	
	function lazyload()
	{
	$.ajax({ url: "files/statistics.php", success: function(data){ $('span#count').html(data); }});
	$.ajax({ url: "../randimgs.php", success: function(data){ $('span#randimgs').html(data); }});
	}
	function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function checkCookie()
{
username=getCookie('username');
if (username!=null && username!="")
{}
else
{
username=('ResimUP.Net');
if (username!=null && username!="")
alert( alertmessage );
{
setCookie('username',username,365);
}
}
}
