$(document).ready(function(){
        
	$('#site').fadeIn(1500);
         
});
window.alert = function() {
    jQuery('<div></div>', {
        html: arguments[0].replace(/\n/, "<br />")
    }).dialog({
        modal: true,
        buttons: {
            Ok: function() {
                $(this).dialog( "close" );
            }
        }

    });
};


	
function closeDivs() {
   var arrayOfDivs = document.getElementsByTagName('div');
   for (var i=0; i < arrayOfDivs.length; i++) {
      var thisDiv = arrayOfDivs[i];
      if (thisDiv.style.display=='block') {
         thisDiv.style.display='none';
      }
   }
}

bkLib.onDomLoaded(function() {
	new nicEditor({iconsPath : 'img/nicEditorIcons.gif', uploadURI : 'http://www.nordik-reisen.ch/nicUpload.php', fullPanel : true}).panelInstance('edit_site');
        new nicEditor({iconsPath : 'img/nicEditorIcons.gif', uploadURI : 'http://www.nordik-reisen.chnicUpload.php', fullPanel : true}).panelInstance('edit_news');
        new nicEditor({iconsPath : 'img/nicEditorIcons.gif', uploadURI : 'http://www.nordik-reisen.ch/nicUpload.php', fullPanel : true}).panelInstance('edit_footer');
        new nicEditor({iconsPath : 'img/nicEditorIcons.gif', uploadURI : 'http://www.nordik-reisen.ch/nicUpload.php', fullPanel : true}).panelInstance('news_add');
        new nicEditor({iconsPath : 'img/nicEditorIcons.gif', uploadURI : 'http://www.nordik-reisen.ch/nicUpload.php', fullPanel : true}).panelInstance('edit_left');
	nicEditors.allTextAreas();
        
});

$(function () {
   
   $( "#click_add" ).click(function() {
			$('#add_panel').fadeIn(1000);
                        $('#confirm_gallery').fadeIn(1000);
			$('#add_file_box').fadeOut(200);
                        $('#file_upload_cover').uploadifyClearQueue();
                        $('#file_upload_bottom').uploadifyClearQueue();
                        $('#file_upload_gallery').uploadifyClearQueue();
   });
    $( "#click_close" ).click(function() {
			$('#add_panel').fadeOut(400);
                        $('#confirm_gallery').fadeOut(200);
			$('#add_file_box').fadeOut(200);
                        $('#file_upload_cover').uploadifyClearQueue();
                        $('#file_upload_bottom').uploadifyClearQueue();
                        $('#file_upload_gallery').uploadifyClearQueue();
   });
   
  
    var cssPrefixString = {};
    var cssPrefix = function(propertie) {
        if (cssPrefixString[propertie]) return cssPrefixString[propertie] + propertie;
        var e = document.createElement('div');
        var prefixes = ['', 'Moz', 'Webkit', 'O', 'ms', 'Khtml']; // Various supports...
        for (var i in prefixes) {
            if (typeof e.style[prefixes[i] + propertie] !== 'undefined') {
                cssPrefixString[propertie] = prefixes[i];
                return prefixes[i] + propertie;
            }
        }
        return false;
    };
   

    var cssTransform = cssPrefix('Transform');
    if (cssTransform ) {
        var cssProp = {};
        cssProp[cssPrefix('borderRadius')] = '15px';
        $('div.boxradius_tools').css(cssProp);
       
    }

    $('#menu_root').clickMenu(); 
     
    $( "#dialog:ui-dialog" ).dialog( "destroy" );
     
    $( "#dialog-modal_login" ).dialog({
        autoOpen: false,
        minHeight: 120,
        width: 450,
        resizable: false,
        modal: true
    });
    $( "#opener_modal_login" ).click(function() {
        $( "#dialog-modal_login" ).dialog( "open" );
        return false;
    });
    
    
    $( "#dialog-modal_edit_left" ).dialog({
        autoOpen: false,
        minHeight: 600,
        width: 830,
        resizable: false,
        modal: true
    });
    $( "#opener_modal_edit_left" ).click(function() {
        $( "#dialog-modal_edit_left" ).dialog( "open" );
        return false;
    });
    
    $( "#dialog-modal_edit_site" ).dialog({
        autoOpen: false,
        minHeight: 600,
        width: 830,
        resizable: false,
        modal: true
    });
    $( "#opener_modal_edit_site" ).click(function() {
        $( "#dialog-modal_edit_site" ).dialog( "open" );
        return false;
    });
    
    $( "#dialog-modal_edit_news" ).dialog({
        autoOpen: false,
        minHeight: 600,
        width: 830,
        resizable: false,
        modal: true
    });
    $( "#opener_modal_edit_news" ).click(function() {
        $( "#dialog-modal_edit_news" ).dialog( "open" );
        return false;
    });
    
    $( "#dialog-modal_edit_gallery" ).dialog({
        autoOpen: false,
        minHeight: 800,
        width: 1000,
        resizable: false,
        modal: true
    });
    $( "#opener_modal_edit_gallery" ).click(function() {
        $( "#dialog-modal_edit_gallery" ).dialog( "open" );
        return false;
    });
    
    
    $( "#dialog-modal_edit_footer" ).dialog({
        autoOpen: false,
        minHeight: 320,
        width: 1040,
        resizable: false,
        modal: true
    });
    $( "#opener_modal_edit_footer" ).click(function() {
        $( "#dialog-modal_edit_footer" ).dialog( "open" );
        return false;
    });
    
     $( "#dialog-modal_newsletter" ).dialog({
        autoOpen: false,
        minHeight: 320,
        width: 1040,
        resizable: false,
        modal: true
    });
    $( "#opener_modal_newsletter" ).click(function() {
        $( "#dialog-modal_newsletter" ).dialog( "open" );
        return false;
    });
    
     $( "#dialog-modal_addnews" ).dialog({
        autoOpen: false,
        minHeight: 320,
        width: 1050,
        resizable: false,
        modal: true
    });
    $( "#opener_modal_addnews" ).click(function() {
        $( "#dialog-modal_addnews" ).dialog( "open" );
        return false;
    });
    
    $( "#dialog-modal_edit_left_photo" ).dialog({
        autoOpen: false,
        minHeight: 700,
        width: 400,
        resizable: false,
        modal: true
    });
    
    $( "#opener_modal_edit_left_photo" ).click(function() {
        $( "#dialog-modal_edit_left_photo" ).dialog( "open" );
        return false;
    });
    
    $("#loginForm").validate({
        rules: {
            pass: "required",
            email: {
                required: true,
                email: true
            }
        },
        messages: {
            pass: "enter password!",
            email: {
                required: "enter email!",
                email: "bad email format!"
            }
        }
    })
    $("#formAddNews").validationEngine();
    $("#formSendEmail").validationEngine();
    $('a.email').nospam({ replaceText: true });
    
});  
