//
//   CF Image Hosting Script 
//   --------------------------
//
//   Author:    codefuture.co.uk
//   Version:   1.4.2
//   Date:      17 June 2011
//
//   download the latest version from - http://codefuture.co.uk/projects/imagehost/
//
//   Copyright (c) 2011 codefuture.co.uk
//   This file is part of the CF Image Hosting Script.
//
//   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
//   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
//   COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
//   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
//   OR  IN  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//
//  You may not modify and/or remove any copyright notices or labels on the software on each
//  page (unless full license is purchase) and in the header of each script source file.
//
//  You should have received a full copy of the LICENSE AGREEMENT along with
//  CF Image Hosting Script.  If not, see http://codefuture.co.uk/projects/imagehost/license/
//   
////////////////////////////////////////////////////////////////////////////////////

//Multiple Upload
	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");
		});
	});

	$(".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');
			$('.upload_form').animate({"height": "210px", "opacity": "100"}, "slow");
		});
		$("#linklocal").click(function(){
			$('#remote_panel').fadeOut(1, function(){$('#local_panel').fadeIn('slow');});
			$('.Upload_Multiple').delay(1).css("display", "block").animate({"height": uploadMultipleBox+"px", "opacity": "100"}, "slow");
			$('#linklocal').removeClass('linklocal').addClass('linklocal show');
			$('#imgUrl').val("");
			$('#linkremote').removeClass('linkremote show').addClass('linkremote');
			$('.upload_form').animate({"height": "55px", "opacity": "100"}, "slow");
		});
	});
	$(document).ready(function(){
		$(".pref_title").live('click',function(){
			$(this).next('.preferences').animate({"height": "toggle", "opacity": "toggle"}, "slow");//slideToggle("slow");
			$(this).toggleClass("open_pref");
		});
	});
//files name
	function copyfileName() 
        {
		var fileInput = document.getElementById("file");
		var ends='';
                
                if(fileInput.files.length > 10) 
                {
                        alert("Maksymalnie 10 plikow");
                        return;
                }
                
                for (var i=0; i<fileInput.files.length; i++) 
                { 
                        if(ends)
                        {
                                ends += ', '+fileInput.files[i].name; 
                        } 
                        else
                        {
                                ends += fileInput.files[i].name; 
                        }
                } 
                
                $('#fileName').val(ends);
	}

// image report
	function doconfirm(message,id,page) {
		if (confirm(message)) {
			var dataString = 'report='+id;
			$.ajax({
				type: "POST",
				url: homeUrl+"/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;
	//	var thisImgWidth;
		$("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 button:
	$(".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;
	});
// FAQ
$(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;
		});
	});
});
