﻿
function confirmSubmit()
{
var agree=confirm("Ootko nyt ihan varma, HÄH?");
if (agree)
	return true ;
else
	return false ;
}



function setIt(){
tinyMCE.activeEditor.setContent($("#"+new_id).html());
}

function closeModalWin()
{
	$("#modali").css({'display' : 'none'});
	$("#jjj").css({'display' : 'none'});
}

function editVideo(title, sql_id, html){
//var elementCount = $("*").css("border","3px solid red").length;
	//tinyMCEPopup.editor.execCommand('mceInsertContent', false, "dfffkjkö");
//$(window.location).attr('href', '#inline1');
//var modal_id = "textBox2";//$(this).attr('name');

//$("#mceEdit").attr("id", "id");
//$("#mceEdit").text("<h3> elements found</h3>");
/*
    var window_width = $(window).width();
    var window_height = $("body").height();
	
        var modal_height = $("#jjj").outerHeight();
        var modal_width = $("#jjj").outerWidth();

        var top = (window_height-modal_height)/2;
		var top = $(window).scrollTop();
        var left = (window_width-modal_width)/2;
		
		$("#jjj").css({'top' : top , 'left' : left});
		$("#modali").css({'top' : 0 , 'left' : 0});
		$("#modali").css({'width' : window_width , 'height' : window_height});
		$("#modali").css({'background-color' : '#ccc', 'opacity' : 0.5 });
		
$("#modali").css({'display' : 'block'});
$("#jjj").css({'display' : 'block'});
*/
//tinyMCE.activeEditor.setContent($("#"+new_id).html());



//tinyMCE.activeEditor.setContent("rwerwrewrw");

//tinyMCE.get('mceEdit').setContent("perlelele");

//$("#"+new_id).html("<textarea id='mceEdit' style='z-index:200;'>"+$("#"+new_id).html()+"</textarea>")

$("#popUpWintoosa").html(html.replace(/<br>/gi,"\n"));



		$.fancybox({
			//'orig'			: $(this),
			'titlePosition'	: 'inside',
			'padding'		: 0,
			'href'			: '#popUpWintoosa', //'http:farm3.static.flickr.com/2687/4220681515_cc4f42d6b9.jpg',
			'title'   		: title,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic'
		});
		

//$("#mceEditId").attr("value", sql_id);
}


function copyTextToEditor(new_id, sql_id, HTMLData){
//var elementCount = $("*").css("border","3px solid red").length;
	//tinyMCEPopup.editor.execCommand('mceInsertContent', false, "dfffkjkö");
//$(window.location).attr('href', '#inline1');
//var modal_id = "textBox2";//$(this).attr('name');

    var window_width = $(window).width();
    var window_height = $("body").height();
	
        var modal_height = $("#jjj").outerHeight();
        var modal_width = $("#jjj").outerWidth();

        var top = (window_height-modal_height)/2;
		var top = $(window).scrollTop();
        var left = (window_width-modal_width)/2;
		
		$("#jjj").css({'top' : top , 'left' : left});
		$("#modali").css({'top' : 0 , 'left' : 0});
		$("#modali").css({'width' : window_width , 'height' : window_height});
		$("#modali").css({'background-color' : '#ccc', 'opacity' : 0.5 });
		
		
$("#modali").css({'display' : 'block'});

//alert($("#jjj:contains(HTMLData").val());

text = $('#ul').html();
//alert(text);
//alert(text.search(HTMLData));
//if($("#jjj").html().indexOf(HTMLData)==-1) $('#jjj').prepend(HTMLData);
//if($("#jjj:contains(HTMLData")<0) $('#jjj').prepend(HTMLData);
if(!text) $('#updater').prepend(HTMLData);


$("#jjj").css({'display' : 'block'});
//tinyMCE.activeEditor.setContent($("#"+new_id).html());

//$("#mceEdit").text("<h3> elements found</h3>");

//tinyMCE.activeEditor.setContent("rwerwrewrw");

//tinyMCE.get('mceEdit').setContent("perlelele");

//$("#"+new_id).html("<textarea id='mceEdit' style='z-index:200;'>"+$("#"+new_id).html()+"</textarea>")

/*
		$.fancybox({
			//'orig'			: $(this),
			'padding'		: 0,
			'href'			: '#inline2', //'http:farm3.static.flickr.com/2687/4220681515_cc4f42d6b9.jpg',
			'title'   		: 'Lorem ipsum dolor sit amet',
			'transitionIn'	: 'none',
			'transitionOut'	: 'none'
		});
*/
		
//tinyMCE.activeEditor.setContent("rwerwrewrw");
		
//show_modal(modal_id);
//tinyMCE.activeEditor.setContent($("#"+new_id).html());
//setTimeout(setIt(),1500);
//alert($("#mceEdit").html());
//alert($("#mceEditId").attr("value"));
tinyMCE.activeEditor.setContent($("#"+new_id).html());
$("#mceEditId").attr("value", sql_id);
//$("#mceEditi").css("border","3px solid red");
//$("#mceEditi").text("<h3> elements found</h3>");
//$("#new_30").html("<h3> elements found</h3>");
//alert('eeee'+document.getElementById('new_30').innerHTML);
//alert('eeee'+document.getElementById('mceEdit').innerHTML);
	//window.document.getElementById('mceEdita').innerHTML = "dddddddddd"; //document.getElementById('new_30').innerHTML;
	//document.getElementById('new_30').innerHTML = "dddddddddd"; //document.getElementById('new_30').innerHTML;
	//tinyMCEPopup.editor.execCommand('mceInsertContent', false, "dfffkjkö");
	//$("mceEditi").innerHTML = "sdadasd";

}

    $(document).ready(function(){
	
	$("#various2").fancybox();

	$("#textBox2").fancybox({
		'titlePosition'		: 'inside',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});
	
	$("#textBox").fancybox({
		'titlePosition'		: 'inside',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});

			$("a[rel=example_group]").fancybox({
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'titlePosition' 	: 'outside',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
    
    //get the height and width of the page
    var window_width = $(window).width();
    var window_height = $(window).height();
    
    //vertical and horizontal centering of modal window(s)
    /*we will use each function so if we have more then 1 
    modal window we center them all*/
    $('.modal_window').each(function(){
        
        //get the height and width of the modal
        var modal_height = $(this).outerHeight();
        var modal_width = $(this).outerWidth();
        
        //calculate top and left offset needed for centering
        var top = (window_height-modal_height)/2;
        var left = (window_width-modal_width)/2;
        
        //apply new top and left css values 
        $(this).css({'top' : top , 'left' : left});
        
    });

        
        $('.activate_modal').click(function(){
		return window.confirm('Continue?');
                
              //get the id of the modal window stored in the name of the activating element       
              var modal_id = $(this).attr('name');
              //alert("de."+modal_id);
              //use the function to show it
              show_modal(modal_id);
              
        });
        
        $('.close_modal').click(function(){
            
            //use the function to close it
            close_modal();
            
        });
        
    });
    
    //THE FUNCTIONS
    
    function close_modal(){
        
        //hide the mask
        $('#mask').fadeOut(500);
        
        //hide modal window(s)
        $('.modal_window').fadeOut(500);
        
    }
    function show_modal(modal_id){
    
        //set display to block and opacity to 0 so we can use fadeTo
        $('#mask').css({ 'display' : 'block', opacity : 0});
        
        //fade in the mask to opacity 0.8 
        $('#mask').fadeTo(500,0.8);
         
         //show the modal window
        $('#'+modal_id).fadeIn(500);
        
    }
