jsReady = false;
sendStr="";

function deleteRow(id)
{                     
    $('#'+id).attr('value', '');
    $('#'+id).parent().parent().hide();
}                   

function addRowService()
{                            
    num = $('#project_newServiceCount').attr('value');
    num++;                                                                          
    id = $('#project_id').attr('value');
    $('#project_newServiceCount').attr('value', num);
    $(".add-service").prev().after("<div class='form-row'"
        +$('#project_service_new_0_en_content').parent().parent().html()
            .replace(/service_new_0/g, "service_new_"+(num-1)) + "</div>")
}                                                       

function addRowExtraContent()
{                            
    num = $('#site_newExtraContent').attr('value');
    num++;                                                                          
    id = $('#site_id').attr('value');
    $('#site_newExtraContent').attr('value', num);
    $(".add-extra-content").prev().after("<div class='form-row'"
        +$('#site_extra_content_new_0_en_subline').parent().parent().html()
            .replace(/extra_content_new_0/g, "extra_content_new_"+(num-1)) + "</div>")
}                                                       

                                        
function browse(id, url)
{
    child = open(url,'', 'scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no')    
    child.currentUrl = "bla bla bla";                              
    setInterval(function(){jQuery("#"+id).attr("value", child.currentUrl)}, 100)
}                                           


function addMediaUrl(id, url, parentWindow)                          
{ 
    alert(id);
    parentWindow.document.getElementById(id).value = url;
    window.close();
}

function isReady()
{
	if (jsReady)
	{
		extractVideoString();
		sendToActionScript(sendStr);
		return true;
	}
	return false;
}

function pageInit() {
	 jsReady = true;
}

function thisMovie(movieName) {
	 if (navigator.appName.indexOf("Microsoft") != -1) {
		 return window[movieName];
	 } else {
		 return document[movieName];
	 }
}

function sendToActionScript(value) {
	 //thisMovie("DEONLOGO").sendToActionScript(value);
	swfobject.getObjectById("DEONLOGO").sendToActionScript(value);
}
function sendToJavaScript(value) {
//     document.forms["form1"].output.value += "ActionScript says: " + value + "\n";
}

function extractVideoString()
{
	var q_split = location.href.split('?');
    var l_split = q_split[0].split('/');
    sendStr="";
    for (var i=3; i<l_split.length; i++)
    {
    	sendStr+=l_split[i];
    	if (i<l_split.length-1)
    	{
    		sendStr+="_";
    	}
    }
	if (sendStr == "") sendStr="start";
	if (l_split[3] == "userpages") sendStr = "ap";
	if (l_split[3] == "upload") sendStr = "ap";
}

         
$(document).ready(function()
{
 
    var params = {};
    params.menu = "false";
    params.scale = "noscale";
	params.wmode = "transparent";
    params.allowScriptAccess = "always";
	var flashvars = {};
	var attributes = { id:"DEONLOGO", name:"DEONLOGO" };
          	
	swfobject.embedSWF("/swf/DEONLOGO.swf", "DEONLOGO", "180", "1024", "8", "expressInstall.swf", flashvars, params, attributes);

	//swfobject.registerObject("DEONLOGO", "8");
	pageInit();
    
    if ($('#project_data_new_0_en_content'))
    {
        $('#project_data_new_0_en_content').parent().parent().hide();
        $('#project_service_new_0_en_content').parent().parent().hide();    
    }                     
    
    if ($('#site_extra_content_new_0_en_subline'))
    {
        $('#site_extra_content_new_0_en_subline').parent().parent().hide();
    }                     
    
        
    if ($('#site_project_id'))
        $('#site_project_id').change(function(){
            id = $('#site_project_id').attr('value')
            for( lang in projectsData[id])
            {
                $('#site_'+lang+'_subline').attr('value', projectsData[id][lang]['subline'])
                $('#site_'+lang+'_body').attr('value', projectsData[id][lang]['body'])                
                $('#site_'+lang+'_headline').attr('value', projectsData[id][lang]['headline'])
            }
        })                                 
    if (jQuery("#loading"))
        jQuery("#loading").hide();
        
    $('ul.menu>li').addClass('level1');
    $('ul.menu>li>ul>li').addClass('level2');
    $('ul.menu>li>ul>li>ul>li').addClass('level3');
            
    $('ul.menu li').each(function(){
        if ($(this).children('ul').length > 0)
        {
            $(this).append('<div class="btn"></div>');
        }
    });
        
    $('ul.menu li>div.btn').click(function(){
        if ($(this).parent().children('ul').length > 0)
        {
            $(this).parent().toggleClass('open');
            return false;
        }        
    });
	
	
	$('ul.menu > li.level1').children('a').click(function(){
        if ($(this).parent().children('ul').length > 0)
        {
            $(this).parent().toggleClass('open');
            return false;
        }      
    });
	

});


function addProjectDataRow()
{                            
    num = $('#project_newProjectDataCount').attr('value');
    num++;                                                                          
    id = $('#project_id').attr('value');
    $('#project_newProjectDataCount').attr('value', num);
    $(".add-project-data").prev().after("<div class='form-row'"
        +$('#project_data_new_0_en_content').parent().parent().html()
            .replace(/data_new_0/g, "data_new_"+(num-1)) + "</div>")
}