/************************************************************************************/
/*                            some markup fixing           		     	            */
/************************************************************************************/

var ie6 = !window.XMLHttpRequest;

var OS = OS || {};

function adjustColumns() {
    var tabsContent = $('.tabsBody');
    var rightBlock = $('#rightBlock');
    var tabs = $('#tabs');

    var headerheight = $('.activeSubheader').height() + 12;
    if (headerheight == 12) headerheight = 0;

    var tabContentHeight = tabs.height() - $('.tabHeaders').height() - 25;
    var rightBlockHeight = rightBlock.height() - 42;

    if (tabContentHeight >= rightBlockHeight) {
        $('#rightBlock .randomLists .content').height(tabContentHeight - $('#rightBlock .upsell').height() - 12);
    } else {
        tabsContent.height(rightBlockHeight - headerheight);
    }
}

/************************************************************************************/
/*                           tabs menu functions           		     	            */
/************************************************************************************/

var tabTimeout;
var timeoutTime = 10;

function showActiveSubmenu() {
	activateTab($('.currentTab'));
}

function showSubmenu(section) {
	clearTimeout(tabTimeout);
	$('.tabsSubheader').each(function() {
		var current = $(this);
		var id = current.attr('id');
		if (section != id) {
			if (!current.hasClass('activeSubheader')) {
				current.hide();
			}
		} else {		    
			current.show();
		}
	});
}

function showActiveSubmenuItem() {

    if (OS.tabIndex.length == 1)
    {
        return;
    }
    var li = $($($('.tabsSubheader')[OS.tabIndex[0]]).children()[OS.tabIndex[1]]);
    li.html(li.children().html());
}

function activateTab(tab) {
	var previous = tab.parent();
	var counter = 0;
	
	$('.tabHeader').each(function() {
		var current = $(this);
		if (current.html() != tab.html()) {
			current.removeClass('active');
			current.removeClass('lastActive');
			previous.removeClass('beforeActive');
			counter++;
		} else {
			if (!current.hasClass('last')) {
				current.addClass('active');
			} else {
				current.addClass('lastActive');
			}
			previous.addClass('beforeActive');
		}
		previous = current;
	});
	var lastSlash=tab.children().attr('href').substring(1).lastIndexOf("/");

	var menu = (tab.children().attr('href').substring(1).substring(lastSlash+1));
	//showSubmenu(tab.children().attr('href').substring(1).replace(/.html/, ''));
	showSubmenu(menu);
}

function initSubMenus() {
    
	//$('.tabsSubheader').hide();
	$('.activeSubheader').show();
	
	$('.tabHeader')
		.mouseover(function() {			
			activateTab($(this));
		})
		.mouseout(function() {
			tabTimeout = setTimeout(showActiveSubmenu, timeoutTime);
		});
	
	$('.tabsSubheader')
		.mouseover(function() {
			var section = $(this).attr('id');
			showSubmenu(section);
		})
		.mouseout(function() {
			tabTimeout = setTimeout(showActiveSubmenu, timeoutTime);
		});
		
	activateTab(
	    $($('.tabHeaders li')[OS.tabIndex[0]]).addClass("currentTab")
	);
	showActiveSubmenuItem();
}

/************************************************************************************/
/*                            	initialization           		     	            */
/************************************************************************************/

$(function() {
    OS.tabIndex = OS.tabIndex || [0,0]
	initSubMenus();
	adjustColumns();
});



/************************************************************************************/
/*                            	Placeholder             		     	            */
/************************************************************************************/


//function inputPlaceholder(input, color) {

//    if (!input) return null;

//    /**
//    * Webkit browsers already implemented placeholder attribute.
//    * This function useless for them.
//    */
//    if (input.placeholder && 'placeholder' in document.createElement(input.tagName)) return input;

//    var placeholder_color = color || '#AAA';
//    var default_color = input.style.color;
//    var italic_style = "italic";
//    var normal_style = "normal";
//   
//    var placeholder = input.getAttribute('placeholder');

//    if (input.value === '' || input.value == placeholder) {
//        input.value = placeholder;
//        input.style.color = placeholder_color;
//        input.style.fontStyle = italic_style;
//    }

//    var add_event = /*@cc_on'attachEvent' || @*/'addEventListener';

//    input[add_event](/*@cc_on'on' + @*/'focus', function() {
//    input.style.color = default_color;
//    input.style.fontStyle = normal_style;
//        if (input.value == placeholder) {
//            input.value = '';
//        }
//    }, false);

//    input[add_event](/*@cc_on'on' + @*/'blur', function() {
//        if (input.value === '') {
//            input.value = placeholder;
//            input.style.fontStyle = italic_style;
//            input.style.color = placeholder_color;
//        } else {
//            input.style.color = default_color;
//        }
//    }, false);

//    input.form && input.form[add_event](/*@cc_on'on' + @*/'submit', function() {
//        if (input.value == placeholder) {
//            input.value = '';
//        }
//    }, false);

//    return input;
//}





