$(document).ready(function() {
    /* button rollovers (delete checked items, 'more' buttons.)
    ----------------------------------------------------------*/
    $('div#lovedItems input.submit').hover(function() {
	    $(this).addClass("submitHover");
	}, function() {
	    $(this).removeClass("submitHover");
	});

    $('div.deal').hover(function() {
        $(this).css("cursor", "pointer");
        $(this).css("background", "#F2F0B8");
    }, function() {
        $(this).css("background", "transparent");
    });

    $("div.deal").click(function() {
        window.location = $(this).attr("url");
        return false;
    });

    fixAlignItemImage(); // Align the images
    setActiveTab(); // first tab will always have css class "active" by default

    // Since our semantic tabs are positioned elements, we need these two functions to properly expand their parent container
    function getTabContentHeight(whichTab) {
        return whichTab.height();
    }

    function setActiveTab() {
        //setParentHeight($('.active').parent().siblings('.tabContent');
        $('.active').parent().siblings('.tabContent').css({
            display: 'block'
        });
        setParentHeight($('.active').parent().siblings('.tabContent'));
    }

    /*$(".tabPanel h3 a").click(function(){
		
		$(".tabPanel h3 a").each(function(){
    $(this).removeClass("active");
    });
		
		$(this).addClass("active");
		
		displayContent($(this));
    // getContent();
    });*/
});

function fixAlignItemImage() {
    $('#lovedItems .itemRow .right').each(function() {
        if ($(this).children('img').length) {
            $(this).addClass('withImage');
        }
    });
}

function displayContent(whichTab) {
		var tc = whichTab.parent().siblings(".tabContent");
		$(".tabContent").each(function(){
			$(this).css("display","none");
		});
		tc.css("display","block");
		setParentHeight(tc);
	}
	
function getContent(){
	// Could do some AJAX here to grab the content	
}

function setParentHeight(whichTabContent){
	var tcH = whichTabContent.height();
	var totalHeight = tcH + 30; //adding the tab content padding. can be changed if necessary.
	//alert(totalHeight);
	$("#interiorTabs").height(totalHeight);
}


function PlotMyTripMarkers(latitude, longitude) {

    // Clear any current map markers
    window.gmap.clearOverlays();
    window.geocoder = new GClientGeocoder();

    // Create a boundary to contain the map zoom
    var bounds = new GLatLngBounds();

    var mainPoint = new GLatLng(latitude, longitude);
    bounds.extend(mainPoint);

    var mainMarker = createMainMarker(mainPoint);
    window.gmap.addOverlay(mainMarker);

    //        // Loop through the results grabbing lat/long
    $('div.mapmarker').each(function() {

        var data = GetMapDataStructure(this);

        if (!isNaN(data.latitude) || !isNaN(data.longitude)) {
            if (jQuery.trim(data.latitude).length > 0 || jQuery.trim(data.longitude).length > 0) {
                // Lat-Lng should be stored in the database
                var point = new GLatLng(data.latitude, data.longitude);
                bounds.extend(point);
                var marker = createMarker(point, data.number, data.name, data.place);
                window.gmap.addOverlay(marker);
            }
        }
    });

    // Center up the display to fit all the results
    if (!bounds.isEmpty())
        window.gmap.setCenter(bounds.getCenter(), window.gmap.getBoundsZoomLevel(bounds));
}

// Recenter and zoom the map for the clicked item
function MapMyTripListing(mapData) {
    var data = GetMapDataStructure(mapData);
    var point = new GLatLng(data.latitude, data.longitude);
    window.gmap.setCenter(point, 12);
}
