$(document).ready(function(){
  $(".datepicker").datepicker();

  $('.articlebanner').each(function(){
    $(this).load( '/inline-banner/' + $(this).attr("id") );
  });

  //	$('.container > .main > .left > .navigation').addClass('treeview-fny');
  //	$('.treeview-fny').treeview({
  //		animated: 'fast',
  //		collapsed: true,
  //		persist: 'location',
  //		unique: false
  //	});

  var preload = [
  '/images/head_button_ingatlan.png', 
  '/images/head_button_halozat.png',
  '/images/head_button_bongeszo.png',
  '/images/head_button_partnereink.png',
  '/images/head_button_ugynok.png',
  '/images/head_button_ingatlan_over.png', 
  '/images/head_button_halozat_over.png',
  '/images/head_button_bongeszo_over.png',
  '/images/head_button_partnereink_over.png',
  '/images/head_button_ugynok_over.png',
  '/images/blue_menu_03.jpg',
  '/images/blue_menu_04.jpg',
  '/images/blue_menu_05.jpg',
  '/images/blue_menu_06.jpg',
  '/images/blue_menu_07.jpg',
  '/images/blue_menu_over_03.jpg',
  '/images/blue_menu_over_04.jpg',
  '/images/blue_menu_over_05.jpg',
  '/images/blue_menu_over_06.jpg',
  '/images/blue_menu_over_07.jpg',
  
  '/images/rotation1_03.png',
  '/images/rotation2_03.png',
  '/images/rotation3_03.png'
  ];

  jQuery.preloadImages = function() {
    var a = (typeof arguments[0] == 'object')? arguments[0] : arguments;
    for(var i = a.length -1; i > 0; i--) {
      jQuery("<img>").attr("src", a[i]);
    }
  }
  $.preloadImages(preload);







});


var MainPopup = {

  status: 0,
  name: '',

  init: function () {

    $("#popup"+name).css({
      "display":"none",
      "position":"fixed",
      "_position":"absolute",
      "height":"280px",
      "width":"408px",
      "background":"#FFFFFF",
      "border":"2px solid #cecece",
      "z-index":"2",
      "padding":"12px",
      "font-size":"13px"
    });

    $("#popup"+name+" h1").css({
      "text-align":"left",
      "color":"#555555",
      "font-size":"22px",
      "font-weight":"700",
      "border-bottom":"1px dotted #555555",
      "padding-bottom":"2px",
      "margin-bottom":"20px"
    });

    $("#popup"+name+"Close").css({
      "line-height":"14px",
      "right":"6px",
      "top":"4px",
      "position":"absolute",
      "color":"#555555",
      "font-weight":"700",
      "display":"block",
      "cursor": "pointer"
    });
  },

  loadPopup: function () {
    if(status == 0){
      $("#backgroundPopup").css({
        "opacity": "0.7"
      });
      $("#backgroundPopup").fadeIn("slow");
      $("#popup"+name).fadeIn("slow");
      status = 1;
    }
  },

  disablePopup: function () {
    if(status == 1){
      $("#backgroundPopup").fadeOut("slow");
      $("#popup"+name).fadeOut("slow");
      popupStatusnewEmail = 0;
    }
  },

  centerPopup: function (){
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#popup"+name).height();
    var popupWidth = $("#popup"+name).width();

    $("#popup"+name).css({
      "position": "absolute",
      "top": windowHeight/2-popupHeight/2,
      "left": windowWidth/2-popupWidth/2
    });


    $("#backgroundPopup").css({
      "height": windowHeight
    });
  }
}

function theRotator() {
	//Set the opacity of all images to 0
	$('div#rotator ul li').css({opacity: 0.0});

	//Get the first image and display it (gets set to full opacity)
	$('div#rotator ul li:first').css({opacity: 1.0});

	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',5000);

}

function rotate() {
	//Get the first image
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));

	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');

};

$(document).ready(function() {
	//Load the slideshow
	theRotator();
});
