// use js (with css) to remove unwanted submit buttons
$('html').addClass('js');

$(function() {
  vFixer();
  userboxToFoot();
  //bannerVisuals();
  setDescHeight();
  menuFixer();
});


function menuFixer() {
	var tallest = 1;
	$('#primary-nav .inner > ul > li').children('ul').each(function(){
		if ($(this).outerHeight() > tallest) tallest = $(this).outerHeight();
	});
	$('#main').css('min-height', (tallest + $('#header').outerHeight()) + 'px');
	
	if (jQuery.browser.msie && (parseInt(jQuery.browser.version) <= 7)) {
		$('#primary-nav .inner > ul > li').mouseover(function(){
			$(this).addClass('hover');
		}).mouseout(function(){
			$(this).removeClass('hover');
		});
	}
	
}

function vFixer() {
	if (jQuery.browser.msie && (parseInt(jQuery.browser.version) == 6 || parseInt(jQuery.browser.version) == 7)) {
		$('.item .signs').css('background', 'transparent');
		$('.item .thumb, .item h2').prepend('<span class="edge"></span>');
	}
}

// inject #userbox into #secondary-nav and show/hide
function userboxToFoot() {
	var $userbox = $('#userbox').remove().clone();
	var heading = $userbox.find('h3').remove().text();
	
	$userbox.hide().append('<span class="arrow a-down"/>');
	$('<li class="item7"/>').insertAfter('#secondary-nav li:first').append('<a href="#" id="act-userbox">' + heading + '</a>').append($userbox);

	// broken IE <9
	if (jQuery.browser.msie && (parseInt(jQuery.browser.version) < 9)) {
		$('#userbox input.submit').click(function(){
			$('#userbox form').submit();
		});
	}
	
	$('#act-userbox').click(function(ev){
		ev.preventDefault();
		$(this).blur();
		$userbox.slideToggle();
		//$('#secondary-nav #userbox .arrow.a-down').slideToggle();
	});
}

/// banner page visuals (eg. home page)
function bannerVisuals() {
	if ($('#banner-page').length > 0) {
		$('#banner-page a').append('<span><i></i></span>');
		$('#banner-page a span, #banner-page a span i').animate({ opacity: 0 }, 0.5).addClass('visible');

		$('#banner-page a').hover(function(){
			showInfo($(this));
		}, function(){
			hideInfo($(this));
		});
		$('#banner-page a').focus(function(){
			showInfo($(this));
		}).blur(function(){
			hideInfo($(this));
		});
	}
}
function showInfo(selector) {
	//selector.find('span').show().addClass('visible');
	selector.find('span, span i').animate({ opacity: 0.5 }, 500);
}
function hideInfo(selector) {
	//selector.find('span').hide().removeClass('visible');
	selector.find('span, span i').animate({ opacity: 0 }, 500);
}


// set the maximum height of the desc
function setDescHeight() {
	var $detDesc = $('#det-desc');

	if ($detDesc.length > 0) {
		var $detDescClone = $detDesc.clone();
		var $detDescClone2 = $detDescClone.clone();
		$detDescClone2.appendTo('body').css({ position: 'absolute', left: '-999em', width: '340px', 'font-family': 'Georgia', 'font-size': '13px', background: '#fff', 'text-align': 'left', 'font-style': 'italic' }).attr('id', 'olddetdesc');
		var detDescHeight = $detDescClone2.height();
		$detDescClone2.remove();

		var detDescPos = $detDesc.position();
		var descContainerMaxHt = $('#det-main-img').height() - ($('#mycarousel').height() ? $('#mycarousel').height() : 0) - ($('#det-params').height() ? $('#det-params').height() : 0) - detDescPos.top;
		
		if (detDescHeight > descContainerMaxHt) {
			$detDesc.height(descContainerMaxHt).addClass('show').autoEllipsis();
			//$detDesc.addClass('show');
			
			
			$('#act-more').live('click', function(event){
				event.preventDefault();
				$('#det-desc').replaceWith($detDescClone);
				$('#det-desc').addClass('show');
			});
		} else {
			$detDesc.addClass('show');
		}
	}

}


$(function() {
    $('.panel_tool_tip').tooltip({
	    track: true,
	    delay: 0,
	    showURL: false,
	    showBody: " - ",
	    opacity: 0.9
    });	 	
    $('.panel_tool_tip img').attr('alt','');
});

$(function() {
    if ($('.form-error').length) {
        $('.form-error a').click(function () {
             var href = $(this).attr('href');
             $(href).focus();
             return false;
         });
     }
});


