/*!	creart Calendar Viewer
	created 2008-14-05 by Christian Schindler | COM.POSiTUM [http://www.compositum.de]
*/

// INIT CALENDAR function
function cc_show(tmpCal) { 
//  alert("creart Calendar Viewer [ " +tmpCal+ " ]");
/*
If you want to make sure that jQuery won't conflict with another library - but you want the benefit of a short name
	var $c = jQuery.noConflict();

	// Use jQuery via $j(...)
	$c(document).ready(function(){
	$c("div").hide();
	});
	
	// Use Prototype with $(...), etc.
	$('someid').hide();
*/
	 
	 
		/*
		There is an issue with using ExternalInterface to call a JavaScript function which in turn launches a popup window or anything in general which steals the window in which your SWF is it’s focus. The object clicked will remain in it’s active state and all mouse events will be locked. Instead of reverting to old-school approaches, I have found success in doing this as a simple workaround.
		Allowing Flash to recieve the success boolean before the focus is stolen is the key to fixing this issue. Again, I’ve only seen this issue in Firefox while running Flash Player 9, but this simple fix is cross-browser compliant.
		*/
         // Set a timeout that will call a function that launches your pop-up window or whatever after Flash has already recieved the success boolean back from this function.
//         window.setTimeout("cc_iCalendar("+tmpCal+")", 200);
//
//         // Return the success as ‘true’.
//         return true;
//}
//
//// APPEND CALENDAR function
//function cc_iCalendar(tmpCal) {
  // append calendar stylesheet to html header
//  $("head").append("<style type='text/css' media='all'>@import 'data/kalendarium/modul/calendar.css';</style>");

//  try {
    // create div layers to darken background
    if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
      $("body","html").css({height: "100%", width: "100%"});
      $("html").css("overflow","hidden");
      // set <html> and <body> overflow=hidden to hide basic flash
//      $("html").css("overflow","hidden");
//      $("body").css("overflow","hidden");
      if (document.getElementById("CC_HideSelect") === null) {//iframe to hide select elements in ie6
	    $("body").append("<iframe id='CC_HideSelect'></iframe><div id='CC_overlay'></div><div id='CC_window'></div>");
      }
    }else{//all others
      if(document.getElementById("CC_overlay") === null){
	    $("body").append("<div id='CC_overlay'></div><div id='CC_window'></div>");
      }
    };

    if(cc_detectMacXFF()){
      $("#CC_overlay").addClass("CC_overlayMacFFBGHack");//use png overlay so hide flash
    } else {
      $("#CC_overlay").addClass("CC_overlayBG");//use background and opacity
    };
  
      // Sizing
      CC_WIDTH = 1000;
      CC_HEIGHT = 650;
  
    // FLASHVARS
    var flashvars2 = {};
        flashvars2.calYear			= tmpCal;

    // PARAMS
    var params2 = {};
        params2.loop 				= "false";
        params2.menu 				= "false";
        params2.quality 			= "high";
        params2.wmode 				= "transparent";
        params2.scale 				= "noBorder";
        params2.bgcolor 			= "#e1e9f1";
        params2.swliveconnect 		= "true";
        params2.allowscriptaccess 	= "always";

    // ATTRIBUTES
    var attributes2 = {};
        attributes2.id 				= "creart_calendar";
        attributes2.name 			= "creart_calendar";
        attributes2.align 			= "top";

    // SWFOBJECT
    swfobject.embedSWF("data/kalendarium/modul/creart_calendar.swf", "creartCalendarViewer", "1000", "650", "9.0.16", false, flashvars2, params2, attributes2);  
	
	  
	  
    // define key functions
    document.onkeydown = function(e){ 
	  if (e == null) { // ie
	    keycode = event.keyCode;
	  } else { // mozilla
	    keycode = e.which;
	  }
//	  if(keycode == 27){ // close
//	    cc_remove();
//	  }
    };
	  
	  
    cc_position();
    $("#CC_window").css({display:"block"}); //for safari using css instead of show
	
	
    if(!params['modal']){
      document.onkeyup = function(e){   
        if (e == null) { // ie
          keycode = event.keyCode;
        } else { // mozilla
          keycode = e.which;
        }
//        if(keycode == 27){ // close
//          cc_remove();
//        }  
      };
    }
    
//  } catch(e) {
//    //nothing here
//  }  
}  
  
// REMOVE function
function cc_remove() {
  // fade out creart calendar viewer
  $("#creart_calendar").fadeOut("fast",function(){$('#CC_window,#CC_overlay,#CC_HideSelect').trigger("unload").unbind().remove();});

  // unset <html> and <body> overflow=hidden
//  $("html").css("overflow","");
//  $("body").css("overflow","");
  
  // remove object#creart_calendar
  $("#creart_calendar").remove();
  
  // remove calendar stylesheet from html header
//  $("style").remove(":contains('calendar.css')");
  
  // create empty layer for new creart calendar viewer
  $("#index").before("<div id='creartCalendarViewer'></div>");

  if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
    $("body","html").css({height: "auto", width: "auto"});
    $("html").css("overflow","");
  }
  document.onkeydown = "";
  document.onkeyup = "";
  return false;
}
   
// POSITIONING function
function cc_position() {
  $("#CC_window").css({marginLeft: '-' + parseInt((CC_WIDTH / 2),10) + 'px', width: CC_WIDTH + 'px'});
  if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
    $("#CC_window").css({marginTop: '-' + parseInt((CC_HEIGHT / 2),10) + 'px'});
  }
}

// DETECT MAC function
function cc_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}