var $j = jQuery;
$j(document).ready(function() {

  /**
   * Creates window on black background
   * @param width Window width
   * @param height Window height      
   */     
  function createWindow(width, height, div_id)
  {
    // Get body width and height
    var body_width = $j('body').width();
    var body_height = $j('body').height();
    // Set body width and height on our element
    //$j('#over').css('width', body_width);
    //$j('#over').css('height', body_height + 20);
    
    // Set width and height on our window
    $j(div_id).css({'width': width - 70, 'height': height - 20});
    // Set margins
    var window_height = $j(window).height();
    var window_width = $j(window).width();
    $j(div_id).css('top', (window_height - height) / 2);
    $j(div_id).css('left', (window_width - width) / 2);

    // Show our window
    $j(div_id).show();    
    $j('.overdiv').css("height", body_height).fadeIn(100);
    $j('#over').fadeIn(100);
    
  }
  
  if ($('#golive').length && $j.cookie('golive') != 'popup') {
    createWindow(600, 370, '#golive');  
    var window_height = $j(window).height();
    $j.cookie('golive', 'popup', { expires: 1, path: '/' });
  };

  
  $j('#close-golive').click(function(){
    $j(this).parent().parent().fadeOut('100');
    $j('.overdiv').hide();
    $j(this).parent().hide();
    return false;
  });
  
  $j('#close-disclaimer').click(function(){
    $j(this).parent().parent().fadeOut('100');
    $j('.overdiv').hide();
    $j(this).parent().hide();
    return false;
  });
  
  // Close window  
  $j('#login-close-window').click(function(){
    $j(this).parent().parent().fadeOut('100');
    $j('.overdiv').hide();
    $j(this).parent().hide();
    // kaskadovite zavrit ostatni okna
    $('#close-golive').click();
    return false;
  });
  
  $j('#reg-close-window').click(function(){
    $j(this).parent().parent().fadeOut('100');
    //$j('#log_in').hide();
    //$j('#golive').hide();
    // kaskadovite zavrit ostatni okna
    $('#login-close-window').click();
    $j('.overdiv').hide();
    $j(this).parent().hide();
    return false;
  });
  
  $j('#contact-close-window').click(function(){
    $j(this).parent().parent().fadeOut('100');
    $j('.overdiv').hide();
    $j(this).parent().hide();
    return false;
  });
  
  // Close window  
  $j('.overdiv').click(function(){
    $j('.overdiv').hide();
    $j('#log_in').hide();
    $j('#registration').hide();
    $j('#contact').hide();
    $j('#golive').hide();
    $j('#disclaimer').hide();
    return false;
  });
  
  
  $j('#disclaimer-link').click(function(){
    createWindow(600, 350, '#disclaimer');
    return false;
  });
  
  // Create contact window
  $j('.contact_link').click(function(){
    createWindow(600, 400, '#contact');
    return false;
  });
    
  // Create login window
  $j('.login_link').click(function(){
    createWindow(600, 550, '#log_in');
    return false;
  });
  
//  // Create login honour window
//  $j('.login_link').click(function(){
//    $('#redirect').val('/honour/?top=3');
//    createWindow(600, 550, '#log_in');
//    return false;
//  });
  
  // Create registration window
  $j('.registration_link').click(function(){
    createWindow(600, 550, '#registration');
    return false;
  });
  
  

$j('#setup_principles').hover(function(){
	$j(this).addClass('yellow');
	$j('#menu_principles').addClass('hover');
  },
  function(){
	$j(this).removeClass('yellow');
	$j('#menu_principles').removeClass('hover');
  });
  
  $j('#setup_resources').hover(function(){
	$j(this).addClass('yellow');
	$j('#menu_resources').addClass('hover');
  },
  function(){
	$j(this).removeClass('yellow');
	$j('#menu_resources').removeClass('hover');
  });
  
  $j('#setup_participate').hover(function(){
	$j(this).addClass('yellow');
	$j('#menu_participate').addClass('hover');
        $j('#green_leaf_awards').addClass('hover');
  },
  function(){
	$j(this).removeClass('yellow');
	$j('#menu_participate').removeClass('hover');
        $j('#green_leaf_awards').removeClass('hover');
  });
  
  
  $j('#menu_principles').hover(function(){
  
	  $j('#setup_principles').addClass('yellow');
	  
  }, function(){
	
    $j('#setup_principles').removeClass('yellow');
  
  });
  
  
  $j('#menu_resources').hover(function(){
  
	  $j('#setup_resources').addClass('yellow');
	  
  }, function(){
	
    $j('#setup_resources').removeClass('yellow');
  
  });
  
  
  $j('#menu_participate').hover(function(){
  
	  $j('#setup_participate').addClass('yellow');
	  
  }, function(){
	
    $j('#setup_participate').removeClass('yellow');
  
  });
  
});
