// $Id$
jQuery.noConflict();

(function($) {
  // Top menu
  jQuery('#topmenu li').each(function(){
    jQuery(this).hover(
      function(){
        jQuery(this).addClass('sfhover');
        jQuery(this).find('ul:eq(0)').show();
      },
      function(){
        jQuery(this).removeClass('sfhover');
        jQuery(this).find('ul:eq(0)').hide();
      }
    );
  });

  if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) <= 7) {
    jQuery('#menu-wrap').hover(
      function(){
        jQuery('#content').css({'z-index': -1});
      },
      function(){
        jQuery('#content').css({'z-index': 0});
      }
    );
  }

  /*
  jQuery('.content-inner:eq(0)').width(
    jQuery('#leftwrap').width() + jQuery('#maincontent').width()+100
  );
  */

  
  jQuery('.content-inner-brother:eq(0)').width(
    jQuery('.content-inner:eq(0)').width()
  );
  
  
  jQuery('.content-inner-brother:eq(0)').height(
    jQuery('.content-inner:eq(0)').height() + 260
  );

	var myWidth = 0, myHeight = 0, subtract;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		subtract = -12;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth + 20;
		subtract = -10;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth + 20;
		subtract = 10;
	}
//alert( (myWidth - jQuery('.wrapper:eq(0)').width() ) / 2);
	jQuery('.content-inner-brother:eq(0)').css('left',	(myWidth - jQuery('.wrapper:eq(0)').width() ) / 2 + subtract);
  function applySectionClass (activePage, url) {
    switch (jQuery.trim(activePage)) {
      case 'Home':
        jQuery('body').addClass('homePage');
        break;
      case 'Fashion Lush':
        jQuery('body').addClass('fashionLush');
        jQuery('#siteName a').html(activePage).attr('href', '/fashion-lush.html');
        break;
      case 'Sex Lush':
        jQuery('body').addClass('sexLush');
        jQuery('#siteName a').html(activePage).attr('href', '/sex-lush.html');
        break;
      case 'Date Lush':
        jQuery('body').addClass('dateLush');
        jQuery('#siteName a').html(activePage).attr('href', '/dating-lush.html');
        break;
      case 'Travel Lush':
        jQuery('body').addClass('travelLush');
        jQuery('#siteName a').html(activePage).attr('href', '/travel-lush.html');
        break;
      case 'Social Lush':
        jQuery('body').addClass('socialLush');
        jQuery('#siteName a').html(activePage).attr('href', '/social-lush.html');
        break;
      case 'Lush Plus':
        jQuery('body').addClass('lushPlus');
        jQuery('#siteName a').html(activePage).attr('href', '/lush-plus.html');
        break;
    }
    
    jQuery('#topmenu ul.menu li a').each(function(){
      if (jQuery(this).attr('href') == url) {
        var activePage = jQuery(this).parent().parent().parent().find('a:eq(0) span').html()
        applySectionClass (activePage, '');
      }
    });
  }
  
  var classAdded = false;
  
  if (jQuery('#topmenu > ul > li.active > a > span').size()) {
    applySectionClass (jQuery('#topmenu > ul > li.active > a > span').html(), '');
    classAdded = true;
  }
  
  if (jQuery('#mainbody .contentpaneopen:eq(0) td').size() >= 4) {
    jQuery('body').addClass('articlePage');
    classAdded = true;
  }
  
  /**
   *
   */
  jQuery('#mainbody table.contentpaneopen span.art_text a:eq(0)').each(function(){
    applySectionClass (
      jQuery(this).html(),
      jQuery(this).attr('href')
    );
  });
  
  if (jQuery('div.write_comment, #_JOOMLACOMMENT_ADDNEW, #_JOOMLACOMMENT_SEARCH').size()) {
    jQuery('body').addClass('blogPage');
  }
  
  if (jQuery('#rightwrap').size() < 1) {
    jQuery('body').addClass('noRight');
  }
  
  if (jQuery('#leftwrap').size() < 1) {
    jQuery('body').addClass('noLeft');
  }
  
  if (jQuery('form[name="adminForm"] textarea[name="text"]').size()) {
    jQuery('body').addClass('noLeft').addClass('noRight');
  }
  
  if (!jQuery('body').attr('class').match(/Lush/i)) {
    jQuery('body').addClass('homePage');
  }
  
  // go back to previous page if current is login form
  if (window.location.href.match(/component\/comprofiler\/login\.html$/i)) {
    history.go(-1);
  }
  
  // Add link to user box
  jQuery('#header #mod_login_logoutform').append('<div id="userLinks"><a href="/my-account.html">My account</a></div>');
  
  // on forum pages, redirect url#anchor to url
  if (jQuery('#Kunena').size() && window.location.href.match('#')) {
    window.location = window.location.href.replace(/#.+$/, '')
  }
})(jQuery);
