/**
 * $Rev: 2953 $
 * $Date: 2010-06-28 11:20:56 -0500 (Mon, 28 Jun 2010) $
 * $Author: jason.neumann $
 * $HeaderURL$
*/
/*******************************************************************************************************
There is a bit of redundancy in quite a few of the functions, this was done on purpose to
not clutter just one function with different cases for each type of travel planner event.
spreading out the code made it easier for debugging purposes. If you modify anything, just make sure
you comment it.
************************************************************************************************************/

function toggleRoom(idNum){
	// This Function is called when Room selector is clicked

	if(jQuery('#tripType').val() == 'car') return;
	// Hide the More Rooms Link if clicking 2 or 3

	var passengerContainer;
	var i;
	var j;
	idNum = parseInt(idNum);
	for(i=1;i <= idNum;i++ ){
			passengerContainer = jQuery('#passengerContainer' + i);
			passengerContainer.show();
            var display = (idNum==1)?"hidden":"visible";
			jQuery('#'+tpInputId['room_number']+"_1").show();
	}
	switch(idNum){
		case 1:
		case 2:for(i=idNum+1;i <= MAX_ROOMS;i++ )
					jQuery('#passengerContainer' + i).hide();
		break;
	}

	var room2 = jQuery('#passengerContainer2');
	var room3 = jQuery('#passengerContainer3');
	if( (room2.is(':visible') || room3.is(':visible') )  && (jQuery('#tripType').val() == 'hotel' || jQuery('#tripType').val() == 'package')){
		jQuery('[id=TP_MoreRooms]').hide();
		jQuery('[id=TP_RoomCount], [id^=TP_RoomCount_]').show();
	}else if(jQuery('#tripType').val() == 'hotel' || jQuery('#tripType').val() == 'package'){
		jQuery('[id=TP_MoreRooms]').show();
		jQuery('[id=TP_RoomCount]').hide();
	}
}

function toggleChildAge(roomNumber,numChildren){
	/* This Function is called when children number selector is clicked */
	var childAgeContainer;
	var i;
	roomNumber  = parseInt(roomNumber);
	numChildren = parseInt(numChildren);

	if(numChildren < 1) {//If zero, nothing is toggled, everything set to display:none
		for(i=1;i <= MAX_CHILDREN;i++)
			jQuery('#childAgeContainer'+roomNumber+i).hide();

		jQuery('#TP_ChildAges_Row_'+ roomNumber).hide();
		return;
	}

    if(numChildren == 1)
        jQuery('#childAgeContainer'+roomNumber+'1 .ageOfChildTitle').html('Age of Child');
    else
        jQuery('#childAgeContainer'+roomNumber+'1 .ageOfChildTitle').html('Age of Child 1');

	jQuery('#TP_ChildAges_Row_'+ roomNumber).show();
	for(i=1;i <= numChildren;i++)
		jQuery('#childAgeContainer'+roomNumber+i).show();

	switch(numChildren){
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
            for(i=numChildren+1;i <= MAX_CHILDREN;i++ )
                jQuery('#childAgeContainer' + roomNumber + i).hide();
	}

}
function showTravelPlannerHotel(){
    hideTpInputs();
	var toInput = jQuery('#'+toId['hotel_input']);
	var toMain	 = jQuery('#'+toId['hotel_main']);
	if(toMain){
		if(toMain.is("select")) {
			jQuery('#TpToHotelContainer').show().find('select').next('span').css({'margin-top':'19px'}).show().find('.customselect').css('margin-top','0');
            //toMain.next('span').show();
        } else {
			jQuery('#TpToHotelContainer').show().find('span').css('display','block');
            //toInput.show().parent().show().parent().show();
        }
    }
	else
        jQuery('#TpToHotelContainer').show().find('span').css('display','block');
		//toInput.show().parent().show().parent().show();

    jQuery('#tripType').val('hotel');
	jQuery('#'+tpInputId['room_container']).show();
	jQuery('#fromInput').hide();

	showOtherRooms(); //show other rooms
	// Check if the travelPlannerAnytime is being used on the page, and adjust the inputs accordingly.
	//if(jQuery('#floatingTP') && jQuery('#shade_pod').hide()){
	//}else
	togglePackageType(true);
    toggleMoreType(false);
	toggleCarTime(false);
}
function showTravelPlannerFlight(lastElement){
	hideTpInputs();
    var elementInput = jQuery('#'+toId['flight_input']);
	var elementMain	 = jQuery('#'+toId['flight_main']);
	if(elementMain.is('select')) {
		jQuery('#TpToFlightContainer').show().find('select').next('span').css({'margin-top':'19px'}).show().find('.customselect').css('margin-top','0');
        //elementMain.next('span').show();
    } else {
        jQuery('#TpToFlightContainer').show().find('span').css('display','block');
		//elementInput.show().parent().show().parent().show();
    }
    //showOtherRooms();
	hideOtherRooms(false); // hide all other rooms
    jQuery('#TP_Rooms').hide();
    jQuery('#tripType').val('flight');
    jQuery('#fromInput').show().find('input').show().end().find('span').css('display','block');//.find('span').css('display','block');

	togglePackageType(true);
    toggleMoreType(false);
	toggleCarTime(false);
}
function showTravelPlannerPackage(){
	hideTpInputs();
    var elementInput = jQuery('#'+toId['package_input']);
	var elementMain	 = jQuery('#'+toId['package_main']);
	if(elementMain.length > 0){
		if(elementMain.is('select')) {
			jQuery('#TpToPackageContainer').show().find('select').next('span').css({'margin-top':'19px'}).show().find('.customselect').css('margin-top','0');

            //elementMain.next('span').show();
        } else {
            jQuery('#TpToPackageContainer').show().find('span').css('display','block');
			//elementInput.show().parent().show().parent().show();
        }
    }
	else
        jQuery('#TpToPackageContainer').show().find('span').css('display','block');
		//elementInput.show(); //.parent().show().parent().show();

	jQuery('#tripType').val('package');
	jQuery('#'+tpInputId['room_container']).show();
	jQuery('#fromInput').show().find('input').show().end().find('span').css('display','block'); //.find('span').css('display','block');

	// If it's set to 'Hotel Only' on radio buttons, change it back to Flight + Car
	/*if (document.forms['tpForm'].pt[2].checked) {
		if (jQuery('#hotelFlightPackageOpt')) {
			selectTripType(jQuery('#hotelFlightPackageOpt'));
			jQuery('#hotelFlightPackageOpt').attr('checked','checked');
		}
	}*/

	showOtherRooms(); //show other rooms
	togglePackageType(true);
    toggleMoreType(false);
	toggleCarTime(false);
}

function showTravelPlannerCar(){
    hideTpInputs();
	var elementInput = jQuery('#'+toId['car_input']);
	var elementMain	 = jQuery('#'+toId['car_main']);
	var roomCount;
	if(elementMain.is("select")) {
		jQuery('#TpToCarContainer').show().find('select').next('span').css({'margin-top':'19px'}).show().find('.customselect').css('margin-top','0');
        //elementMain.next('span').show();
    } else {
        jQuery('#TpToCarContainer').show().find('span').css('display','block');
		//elementInput.show().parent().show().parent().show();
    }
	jQuery('#tripType').val('car');
	jQuery('#'+tpInputId['room_container']).hide(); //hide room container
	jQuery('#fromInput').hide();

	hideOtherRooms(true); //hide all other rooms
	togglePackageType(false); //hide package type
    toggleMoreType(true);
	toggleCarTime(true);
}
function setHotelLocation(areaName){
	var elementInput = jQuery('#'+toId['hotel_input']);
	var elementMain	 = jQuery('#'+toId['hotel_main']);

	elementMain.val(areaName);

}
function setPackageLocation(areaName){
	if(jQuery('#'+toId['package_main']).is('input')){
		var elementInput = jQuery('#'+toId['package_input']);
		elementInput.val(areaName);
		var toTargetObj	= jQuery('#'+toId['package_main']);
		toTargetObj.val(areaName.substr(-4,3));
	}
	else{
		jQuery('#'+toId['package_input']).val(areaName);
		jQuery('#'+toId['package_main'] + '_hidden').val(areaName.substr(-4,3));
	}

}
function togglePackageType(show){
	if(show == true)
		jQuery('#'+tpInputId['package_type']).show();
	else
		jQuery('#'+tpInputId['package_type']).hide();
}
function toggleMoreType(show) {
    if(show == true)
        jQuery('#'+tpInputId['more_type']).show();
    else
        jQuery('#'+tpInputId['more_type']).hide();
}
function selectTripType(elem){
	jQuery(".tp_pack_radio").css('font-weight','normal');
	jQuery(elem).attr('checked', true).parent().css('font-weight','bold');
}
/**
 * Fixes an issue if user reloads the page and a radio was checked, will remember
 * the last guest action so we can then have the correct tab selected.
 * Reverse correlation to the tabs select, we check the radio.
 */
function selectTripTypeOnLoad() {
    /*var trip_type = jQuery('input[name=pt]:checked');
    var trip_value = trip_type.val();
    console.log(trip_value);
    selectTripType(trip_type);
    if(trip_value == 'hf' || trip_value == 'hfc')
        return toggleTpTab('tpPackage');
    else if(trip_value == 'h')
        return toggleTpTab('tpHotels');
    else if(trip_value == 'f')
        return toggleTpTab('tpFlights');*/

    var trip_type = jQuery('input[name=pt]:checked');
    if(trip_type && trip_type.length)
    selectTripType(trip_type);

    var trip_type_input = jQuery('#tripType');
    if(trip_type_input && trip_type_input.length) {
        var trip_value_input = trip_type_input.val();
        if(trip_value_input.length > 0) {
            if(trip_value_input == 'package')
                return toggleTpTab('tpPackage');
            if(trip_value_input == 'hotel')
                return toggleTpTab('tpHotels');
            if(trip_value_input == 'flight')
                return toggleTpTab('tpFlights');
            if(trip_value_input == 'car')
                return toggleTpTab('tpCarTab');
        }
    }
    return true;
}
function toggleCarTime(show){
	if(show == true)
		jQuery('#'+tpInputId['car_time_container']).show();
	else
		jQuery('#'+tpInputId['car_time_container']).hide();
}
function hideOtherRooms(hideAll){
	var i;
	if(hideAll!=false){
		var roomCount = jQuery('#TP_Rooms').children('div').children('.selected_display').html();
	}
	else
		{
			var roomCount=1;
			jQuery('#TP_RoomCount').hide();
		}
	    tpKids1 = jQuery('#TP_Children_1').children('div').children('.selected_display').html();
		
		var totalRooms=jQuery('#rm').val();
		for(j=1;j<=totalRooms;j++)
		{
			totalKids=parseInt(jQuery('#TP_Children_'+j).children('div').children('.selected_display').html());
		}
		for(j=1;j<=totalKids;j++)
		{
			jQuery('#childAgeContainer1' +j).show();
		}
		if(parseInt(tpKids1)>1){
			jQuery('#childAgeContainer11').children('.ageOfChildTitle').html('Age of Child 1');
		}
		if(parseInt(tpKids1)>0){
			jQuery('#TP_ChildAges_Row_1').show();
		}
		jQuery('.passengerContainer').hide();

		if(roomCount >= 1){
			for(i=1;i<=roomCount;i++){
				jQuery('#passengerContainer' + i).show();
			}
		}
		jQuery('.ageOfChildContainer').children('div').children('.selected_display').html('Select');
}
// This is called only with package and hotel tabs
function showOtherRooms(){
	var i;
	//Display all Rooms Adults and Kids
		tpRooms1 = jQuery('#TP_Rooms').children('div').children('.selected_display').html();
		jQuery('.childAgeContainer').hide();
		jQuery('#TP_RoomCount').show();
		for(i=1;i<=tpRooms1;i++){
			tpKids1 = jQuery('#TP_Children_'+i).children('div').children('.selected_display').html();
				for(j=1;j<=tpKids1;j++){
					jQuery('#childAgeContainer' + i+j).show();
				}
		}
	var roomCount	= jQuery('#'+tpInputId['room_input']).val();
	jQuery('#'+tpInputId['room_number']+'_1').css('visibility','visible').show();//.show(); //show room count for first room
    for(i=1; i <= roomCount;i++) {
        var seperator = (i >= 2) ? "'border-top','1px solid #999'":'';
        jQuery('#passengerContainer' + i).show().css(seperator);
    }
}
function hideTpInputs() {
    jQuery('#TpToHotelContainer, #TpToFlightContainer, #TpToPackageContainer, #TpToCarContainer').hide();
}
// Deprecated, replaced with jquery sitecalendar ~ JP
function showCalendar(fd,action,opt){
	var tripType = jQuery('tripType').val();
	var fdTitle = dates[tripType + '_fd_title'];
	var tdTitle = dates[tripType + '_td_title'];
	var title = (fd=="fd") ? fdTitle : tdTitle;

	var theOpts = eval("({"+opt+"})");
	if (theOpts.header && theOpts.header != "Return" && theOpts.header != "Depart")
		opt = opt.replace(/header:'.*?'/,"header:'"+title+"'");

	eval("Calendar."+action+"({"+opt+"});");
}
function showCalendarSBR(fd,action,opt){
	eval("Calendar."+action+"({"+opt+"});");
}
function changeTitles(){
	var tripType 	= jQuery('#tripType').val();
	var fdTitleObj	= jQuery('#fdTitle');
	var tdTitleObj	= jQuery('#tdTitle');
	var toTitleObj	= jQuery('#toTitle');

	var fdTitle = dates[tripType + '_fd_title'];
	var tdTitle = dates[tripType + '_td_title'];
	var toTitle = toId[tripType + '_to_title'];

	fdTitleObj.html(fdTitle);
	tdTitleObj.html(tdTitle);
	toTitleObj.html(toTitle);

    // change the calendar header by changing the input title attr
    var fdTitleCal = dates[tripType+'_fd_title_cal'];
    var tdTitleCal = dates[tripType+'_td_title_cal'];
    jQuery('#fd').attr('title', fdTitleCal);
    jQuery('#td').attr('title', tdTitleCal);
}
function setPackageArea(concatString){
		/**
		 * This function is only called when there are pre-selected
		 * destinations for packages such as when you visit orlando.bookit.com
		 * it will be a concatinated stirng as follows... locationId:areaId:areaName
		 */
	if(concatString.indexOf(":") > 0){
		var pieces = concatString.split(":");
		jQuery('#'+toId['package_main'] + '_hidden').val(pieces[0]);
		jQuery('#'+toId['package_main_alt']).val(pieces[1]);
		jQuery('#'+toId['package_input']).val(pieces[2]);
	}
}

function setHotelToLocation(locationId,locationText,tripType,setText,areaId){
	jQuery('#'+toId[tripType + '_input']).val(locationText);
	hideLocationList('hotelTo');
}

function setToLocation(locationId,locationText,tripType,setText,areaId){
	if(tripType == "checktype"){ //if checktype passed, we look for the type in the hidden input
          tripType = jQuery('#tripType').val();
     }

	toInputObj = jQuery('#'+toId[tripType + '_input']);
	toTargetObj = jQuery('#'+toId[tripType + '_main']);

	//if(setText == true)
		toInputObj.val(locationText);

    /*If areaId is attached to locationId i.e. hawaii */
	if(areaId!=''){
		if(jQuery('#'+toId[tripType + '_main_alt'])){
			jQuery('#'+toId[tripType + '_main_alt']).val(areaId);
		}
	}
    else{
        if(jQuery('#'+toId[tripType + '_main_alt'])){
			jQuery('#'+toId[tripType + '_main_alt']).val('');
        }
     }
	toTargetObj.val(locationId);
	hideLocationList('to');
}
function setFromLocation(locationId,locationText,tripType,setText, onSuccessEvent, doNotUpdateFromLocationDisplay){
	/*
    var first = document.getElementById("FROMFinderSave");
	var select = first.getElementsByTagName("select");
	*/
    var fromInputObj  = jQuery('#'+tpInputId['from_input']);
	var fromTargetObj = jQuery('#'+tpInputId['from_main']);

    locationId = (locationId && locationId.length > 0) ? locationId : '';

    jQuery.ajax({
        url : 'ajaxRedirect.php',
        type : 'post',
        dataType : 'json',
        async : false,
        data : ({
            action : 'server_setfromlocation.php',
            fromLocation : locationId
        }),
        error : function(XMLHttpRequest, textStatus, errorThrown){
            //alert(XMLHttpRequest +' '+ textStatus +' '+ errorThrown);
        },
        success : function(res) {
            // Should always return a valid location response.
            var state = res.state;
            var city = res.city;
            var country = res.country;
            var locationId = res.locationId;
            var majorState = res.majorState;
            var majorCity = res.majorCity;
            var majorLocationId = res.majorLocationId;

            //update from location in the navigation
            var navAirportName;
            (majorCity && majorCity.length > 12)? navAirportName = majorCity.substring(0,12)+'...' : navAirportName = majorCity;
            var stateTxt = (state && state.length > 0) ? ', '+state : '';
            var countryTxt = (country && country.length > 0) ? ', '+country : '';
            //if(setText == true) {
            fromInputObj.val(city + stateTxt + countryTxt +' (' + locationId + ')');
            fromTargetObj.val(locationId);
            //}

				//if the element updating the page is the from location in the travel planner, dont update
				if(doNotUpdateFromLocationDisplay === true){}
				else{
					jQuery('.siteNav .fromLocation').html(navAirportName);
					//update the display in any other custom selects on the page
					jQuery('span.airport .customselect .selected_display,#airportbubble .customselect .selected_display').html(majorCity + ' (' + majorLocationId + ')');
					//if we are on a page w a promo, update the promo's from location
					jQuery('.packagePromo').find('.From').html('From ' + majorCity + ' (' + majorLocationId + ')');
				}
            if(onSuccessEvent && onSuccessEvent.length > 0)
                eval(onSuccessEvent);
        },
        complete : function(XMLHttpRequest, textStatus) {
            hideLocationList('from');
        }

    });
}
function saveAndhideLocationList(type){
	var locationId;
	var locationText;
	var locationAreaId;
	var tripType;
	var showText;
	if(jQuery('#listLocationId0')){
		locationId 		= jQuery('#listLocationId0').val();
		locationText	= jQuery('#listLocationText0').val();
		locationAreaId  = jQuery('#listLocationAreaId0').val();
		tripType		= jQuery('#tripType').val();
			if(type == 'to'){
				/*
				if(tripType != "package")
					showText = true;
				else
					showText = false;
				*/
			    showText = true;
				setToLocation(locationId,locationText,tripType,showText,locationAreaId);
			}
			else if(type == 'from'){
				setFromLocation(locationId,locationText,tripType,true, "", true);
			}
			else if(type == 'hotelTo'){
				hideLocationList('hotelTo');
			}
	}

}
function hideLocationList(type){
	var targetId;

	if(type == 'to')
		targetId = 'toLocationList';
	else if(type == 'from')
		targetId = 'fromLocationList';
	else if(type == 'hotelTo')
		targetId = 'hotelLocationList';

	jQuery('#'+targetId).html('').hide();
}

//this is used to show and hide the add and remove nights pod
function showAddRemove(){
    if(jQuery('.showAddRemove').css('display') == 'block'){
        jQuery('.showAddRemove').hide();
        jQuery('.addRemoveSubContainer').css({'background' : 'none'});
        jQuery('.addRemoveSubContainer').animate({
             width: "248px",
             borderWidth: '0px',
              height: "20px"
          }, 300 );
    }else{
        jQuery('.showAddRemove').show();
        jQuery('.addRemoveSubContainer').css({'border' : '0px solid #c4c4c4', 'position' : 'absolute', 'background' : '#fff'});
        jQuery('.addRemoveSubContainer').animate({
             width: "200px",
             borderWidth: '1px',
             height: "130px"
          }, 300 );
    }
}

//this changes the display of the text in the add/remove nights pod when the user selects add or remove
function showAddRemoveSelect(){
	var maxRemoveNights = 0;
	var options = "";
	var currentSelection = jQuery("#numNights :selected").val();

	jQuery("#numNights").empty();

	if(jQuery("#addRemoveSelectID :selected").val() == "remove"){
		jQuery("#addRemoveText").replaceWith('<span id="addRemoveText">from the </span>');
		maxRemoveNights = document.getElementById("maxRemove").value;
	}else{
		jQuery("#addRemoveText").replaceWith('<span id="addRemoveText">to the </span>');
		maxRemoveNights = 7;
	}

	for(i = 1; i <= maxRemoveNights; i++){
		options += "<option value='" + i + "'";
		if(i == currentSelection)
			options += " selected=selected";

		options += " >" + i;

		if(i == 1)
			options += " night</option>";
		else
			options += " nights</option>"
	}

	jQuery("#numNights").html(options);

}

//this handles the adding and removing of nights
function changeNights(){
	try{
		var url = window.location.href;
		var numNights = parseInt(jQuery('#numNights :selected').val());
		var changeDate, varName;

		//determine if we are adding or subtracting
		switch (jQuery('#addDatesWhere :selected').val()){
			case "beginning":
				changeDate = jQuery('[name=fd]').val().split('-');
				changeDate = new Date(changeDate[0], changeDate[1] - 1, changeDate[2]);
				varName = "fd";

				switch(jQuery('#addRemoveSelectID :selected').val()){
					case "add":
						changeDate.setDate(changeDate.getDate() - numNights);
						break;
					case "remove":
						changeDate.setDate(changeDate.getDate() + numNights);
						break;
					default:
						throw new Exception("Invalid date operation");
				}
				break;
			case "end":
				changeDate = jQuery('[name=td]').val().split('-');
				changeDate = new Date(changeDate[0], changeDate[1] - 1, changeDate[2]);
				varName = "td";

				switch(jQuery('#addRemoveSelectID :selected').val()){
					case "add":
						changeDate.setDate(changeDate.getDate() + numNights);
						break;
					case "remove":
						changeDate.setDate(changeDate.getDate() - numNights);
						break;
					default:
						throw new Exception("Invalid date operation");
				}
				break;
			default:
				throw new Exception("Invalid date location");
		}

		// we need to get the room id and make sure we are passing the proper one back when the page is re-submitted
		var room = jQuery('[name=roomId]:checked').val();
		url = url.replace(new RegExp("&roomId=.*?&"), "&roomId=" + room + "&");

		var newDate = changeDate.getFullYear() + "-" + ((changeDate.getMonth() < 9) ? "0":"") + (changeDate.getMonth() + 1) + "-" + ((changeDate.getDate() < 10) ? "0":"") + changeDate.getDate();
		url = url.replace(new RegExp("&" + varName + "=.*?&"), "&" + varName + "=" + newDate + "&");
		window.location = url;

	}catch (e){
		//alert(e);
	}
}
function togglePromoCode (PromoCode){
    PromoCodeForm 		= document.getElementById('TP_PromoCodeInput');
    toggleSwitch	= document.getElementById('toggleSwitchPromoCode');
    var btn = 'I Have a Coupon';
    var btn2 = '';
    if(PromoCodeForm.style.display == "none"){
        $(PromoCodeForm).css('display', '');
        toggleSwitch.innerHTML = btn2;
    }
    else{
        $(PromoCodeForm).css('display', 'none');
        toggleSwitch.innerHTML = btn;
    }
}
function toggleWhatPromo (WhatPromo){
    WhatPromoForm 		= document.getElementById('TP_WhatPromo');
    toggleSwitch	= document.getElementById('toggleSwitchWhatPromo');
    var btn = 'What\'s This?';
    var btn2 = 'Close';
    if(WhatPromoForm.style.display == "none"){
        $(WhatPromoForm).css('display', '');
        toggleSwitch.innerHTML = btn2;
    }
    else{
        $(WhatPromoForm).css('display', 'none');
        toggleSwitch.innerHTML = btn;
    }
}
function toggleNeedIdeas (NeedIdeas){
    NeedIdeasForm 		= document.getElementById('TP_NeedIdeas');
    toggleSwitch	= document.getElementById('toggleSwitchNeedIdeas');
    var btn = 'Need Ideas?';
    var btn2 = 'Close';
    if(NeedIdeasForm.style.display == "none"){
        $(NeedIdeasForm).css('display', '');
        toggleSwitch.innerHTML = btn2;
    }
    else{
        $(NeedIdeasForm).css('display', 'none');
        toggleSwitch.innerHTML = btn;
    }
}
/* This checks to see if the travelPlannerAnytime is used, and Adjusts radio button and text accordingly. */
function toggleHotleOnlyCase(obj){
    if(jQuery('#floatingTP') && !jQuery('#shade_pod').is(':visible')){
        /* Do nothing. */
    }else{
        obj.checked = false;
        jQuery('#hotelFlightPackageOpt').attr('checked','checked');
        selectTripType(jQuery('#hotelFlightPackageOpt'));
    }
}

function toggleMoreTabList(cta) {
    var cta = jQuery(cta);
    var ul = cta.next('ul');
    var is_on = cta.hasClass('moreTitleOn');
    var was_on = cta.hasClass('moreTitleWasOn');
    var is_carrot = (is_on || was_on) ? true : false;
    if(ul.is(':visible')){
        if(is_carrot)
            cta.addClass('moreTitleOn').removeClass('moreTitleWasOn');
        cta.find('span').removeClass('close');
        ul.hide();
    } else {
        if(is_carrot)
            cta.removeClass('moreTitleOn').addClass('moreTitleWasOn');
        cta.find('span').addClass('close');
        ul.show();
    }
}
jQuery(document).ready(function(){
    jQuery('body').click(function(){
        var more_span = jQuery('#tpMoreTab .moreSpan');
        if(!jQuery('#tpMoreTab').hasClass('hovered'))
            more_span.removeClass('close').closest('#tpMoreTab').find('.TP_moreList').hide();
    });
    jQuery('#tpMoreTab, #tpMoreTab ul').hover(function(){
        jQuery('#tpMoreTab, #tpMoreTab ul').addClass('hovered');
    },function(){
        jQuery('#tpMoreTab, #tpMoreTab ul').removeClass('hovered');
    });
});
