﻿var MapHolder;
var windowOpts = {
    maxWidth : 280
}

var opts = { clickable: false }
var numListings = 0;


function GSW_mapINIT() {
    if (GBrowserIsCompatible()) {
        var docID = document.getElementById("map_canvas");
        MapHolder = new GMap2(docID);
        MapHolder.enableGoogleBar();
        MapHolder.setCenter(new GLatLng(-45.032940, 168.659280), 15);
        MapHolder.setUIToDefault();

        //add all the listing markers
        var y;
        for (y in markersListing) {
            if (markersListing[y].showItem == true) {
                MapHolder.addOverlay(markersListing[y]);
                var v = $("#Listing_" + y)[0];
                markersListing[y].bindInfoWindow(v.innerHTML, windowOpts);
            }
        }

        //add all the activity markers
        for (y in markersActivity) {
            if (markersActivity[y].showItem == true) {
                MapHolder.addOverlay(markersActivity[y]);
                var v = $("#Activity_" + y)[0];
                markersActivity[y].bindInfoWindow(v.innerHTML, windowOpts);
            }
        }

        //add all the accommodation markers
        for (y in markersAccommodation) {
            if (markersAccommodation[y].showItem == true) {
                MapHolder.addOverlay(markersAccommodation[y]);
                var v = $("#Accommodation_" + y)[0];
                markersAccommodation[y].bindInfoWindow(v.innerHTML, windowOpts);
            }
        }
    }
}


function GSW_showListingsOfType(showOfType) {


    $(".tab").removeClass("selected");
    $("#map_canvas").fadeTo(50, 0.7);
    $("#map_canvas").fadeTo(50, 100);

    for (y in markersListing) {
        markersListing[y].closeInfoWindow();
        markersListing[y].hide();

        $("#ListingItem_" + y).css("display", "none");
    } 
 
    for (y in markersActivity) {
        markersActivity[y].closeInfoWindow();
        markersActivity[y].hide();

        $("#ActivityItem_" + y).css("display", "none");
        $("#ActivityTitle").css("display", "none");

    }

    for (y in markersAccommodation) {
        markersAccommodation[y].closeInfoWindow();
        markersAccommodation[y].hide();

        $("#AccommodationItem_" + y).css("display", "none");
        $("#AccommodationTitle").css("display", "none");

    }

    if (showOfType == "aCafe") {
        for (y in markersListing) {
            var x = markersListing[y].isCafe;
            var z = markersListing[y].showItem;
            if (x == true && z == true) {
                markersListing[y].show();
                $("#ListingItem_" + y).css("display", "block");

            }
        }
        $("#Cafes").addClass("selected");
        $("#ListingTypeTitle").text("Cafes");
    }

    else if (showOfType == "aBar") {
        for (y in markersListing) {
            var x = markersListing[y].isBar
            var z = markersListing[y].showItem;
            if (x == true && z == true) {
                markersListing[y].show();
                $("#ListingItem_" + y).css("display", "block");

            }
        }
        $("#Bars").addClass("selected");
        $("#ListingTypeTitle").text("Bars");
    }

    else if (showOfType == "aRest") {
        for (y in markersListing) {
            var x = markersListing[y].isRestaurant
            var z = markersListing[y].showItem;
            if (x == true && z == true) {
                markersListing[y].show();
                $("#ListingItem_" + y).css("display", "block");

            }
        }
        $("#Restaurants").addClass("selected");
        $("#ListingTypeTitle").text("Restaurants");
    }

    else if (showOfType == "aAct") {
        for (y in markersActivity) {
            var z = markersActivity[y].showItem;
            if (z == true) {
                markersActivity[y].show();
                $("#ActivityItem_" + y).css("display", "block");

            }
        }
        $("#Activities").addClass("selected");
        $("#ListingTypeTitle").text("Activities");
    }

    else if (showOfType == "aAcc") {
        for (y in markersAccommodation) {
            var z = markersAccommodation[y].showItem;
            if (z == true) {
                markersAccommodation[y].show();
                $("#AccommodationItem_" + y).css("display", "block");

            }
        }
        $("#Accommodation").addClass("selected");
        $("#ListingTypeTitle").text("Accommodation");
    }

    else {
        for (y in markersListing) {
            var z = markersListing[y].showItem;
            if (z == true) {
                markersListing[y].show();
                $("#ListingItem_" + y).css("display", "block");
            }
        }

        for (y in markersActivity) {
            var z = markersActivity[y].showItem;
            if (z == true) {
                markersActivity[y].show();
                $("#ActivityItem_" + y).css("display", "block");
            }
        }

        for (y in markersAccommodation) {
            var z = markersAccommodation[y].showItem;
            if (z == true) {
                markersAccommodation[y].show();
                $("#AccommodationItem_" + y).css("display", "block");

            }
        }
        
        $("#ShowAll").addClass("selected");
        $("#ListingTypeTitle").text("All Listings");
        $("#ActivityTitle").css("display", "block");
        $("#AccommodationTitle").css("display", "block");
    
    }
}




function GSW_showInfoBubble(itemIndex, type) {


    //0 = listing : 1 = activity : 2 = accommodation

    if (type == 0) {
        MapHolder.panTo(markersListing[itemIndex].getLatLng());
        var v = $("#Listing_" + itemIndex)[0];
        markersListing[itemIndex].openInfoWindow(v.innerHTML, windowOpts);
    }

    else if (type == 1) {
        MapHolder.panTo(markersActivity[itemIndex].getLatLng());
        var v = $("#Activity_" + itemIndex)[0];
        markersActivity[itemIndex].openInfoWindow(v.innerHTML, windowOpts);

    }

    else if (type == 2) {
        MapHolder.panTo(markersAccommodation[itemIndex].getLatLng());
        var v = $("#Accommodation_" + itemIndex)[0];
        markersAccommodation[itemIndex].openInfoWindow(v.innerHTML, windowOpts);

    }
}

// main map page modal

function showModal(value, type) {
    var id = "#dialog";
    $(".hidden").css("display", "none");
    // 0 = listing : 1 = activity : 2 = accommodation
    if (type == 0) {
        $("#Name_" + value).css("display", "block");
    }
    else if (type == 1) {
        $("#ActivityName_" + value).css("display", "block");
    }
    else if (type == 2) {
        $("#AccommodationName_" + value).css("display", "block");
    }


    //Get the screen height and width  
    var maskHeight = $(document).height();
    var maskWidth = $(document).width();

    //Set height and width to mask to fill up the whole screen  
    $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

    //transition effect       
    $('#mask').fadeIn(500);
    $('#mask').fadeTo("slow", 0.8);

    //Get the window height and width  
    var winH = $(window).height();
    var winW = $(window).width();

    //Set the popup window to center  
    $(id).css('top', winH / 2 - $(id).height() / 2);
    $(id).css('left', winW / 2 - $(id).width() / 2);

    //transition effect  
    $(id).fadeIn(1000);

}





//Map for Accommodation Items


function GSW_MapLocationOfItem(zoom) {

    if (GBrowserIsCompatible()) {

        var map = new GMap2(document.getElementById("map_canvas"));

        var Lat = $("#LatHolder").text();
        var Lon = $("#LonHolder").text();

        var center = new GLatLng(Lat, Lon);

        map.setCenter(center, zoom);
        var marker = new GMarker(center);
        map.setUIToDefault();
        map.addOverlay(marker);
    }
}



//Main Page Boxes

function GSW_Home_Boxes(){

    var cssUp = {
        'background-position': '185px -6px'
    }
    
    var cssDown = {
        'background-position': '185px 6px'
    }


var box1ContentHeight = $("#Box1 .body").height() + $("#Box1 .title").height() + 5;
var box2ContentHeight = $("#Box2 .body").height() + $("#Box2 .title").height() + 5;
var box3ContentHeight = $("#Box3 .body").height() + $("#Box3 .title").height() + 5;

        
        $("#Box1 .headerWrapper, #Box1 .contentWrapper").hover(
          function() {

        $("#Box1 .title").css(cssUp);
        $("#Box1 .content").animate({
                height: box1ContentHeight
              }, { queue: false, duration: 300 });
          },
          function() {
            $("#Box1 .title").css(cssDown)
              $("#Box1 .content").animate({
                   height: "20px"
              }, { queue: false, duration: 300 });
          }
    );

    $("#Box2 .headerWrapper, #Box2 .contentWrapper").hover(
          function() {
              $("#Box2 .title").css(cssUp);
              $("#Box2 .content").animate({
                    height: box2ContentHeight
              }, { queue: false, duration: 300 });
          },
          function() {
              $("#Box2 .title").css(cssDown);
              $("#Box2 .content").animate({
                   height: "20px"
              }, { queue: false, duration: 300 });
          }
    );

    $("#Box3 .headerWrapper, #Box3 .contentWrapper").hover(
          function() {
              $("#Box3 .title").css(cssUp);
              $("#Box3 .content").animate({
                   height: box3ContentHeight
              }, { queue: false, duration: 300 });
          },
          function() {
              $("#Box3 .title").css(cssDown);
              $("#Box3 .content").animate({
                  height: "20px"
              }, { queue: false, duration: 300 });
          }
    );  

}




//Tab Feature

var mouseIn = false;
var t;

var currentPos = -1;
var mouseEntryPos;
var numItems;

function GSW_Set_Pos(index) {
    mouseEntryPos = index; 
}

function GSW_Feature_showItem(arg) {
    // when a mouse enter event calls this function, check the current position and reload only if position has changed
    if (arg == "mouseEnter") {
        if (mouseEntryPos != currentPos) {
            $(".imageWrapper > img").css("display", "none");
            var x = "#item_" + mouseEntryPos + "> .imageWrapper > img";
            $(x).fadeIn("slow");
            $(".tab").removeClass("selected");
            $("#tab_" + mouseEntryPos).addClass("selected");
            currentPos = mouseEntryPos;//set the current position to the new position
        } 
    } 
    else {
        $(".imageWrapper > img").css("display", "none");
        var x = "#item_" + currentPos + "> .imageWrapper > img";
        $(x).fadeIn("slow");
        $(".tab").removeClass("selected");
        $("#tab_" + currentPos).addClass("selected");
    }
}



function GSW_Feature_updateDisplay() {
    
    if (mouseIn == false) {        
        GSW_Feature_calculateNext();
    }
    t = setTimeout("GSW_Feature_updateDisplay()", 4000);
}

function GSW_Feature_calculateNext() {
    numItems = $(".itemWrapper").length;
    currentPos = currentPos + 1;
    if (currentPos == numItems) { currentPos = 0 };
    GSW_Feature_showItem();    
}


function GSW_Feature_MouseIn() {
    mouseIn = true;    
}

function GSW_Feature_MouseOut() {
    mouseIn = false;
}






/*
//Video Page
var index;
var isChanging = false;//variable used to stop video being changed while loading

//fades the clip only if it's not in currently fading and different clip has been chosen
function GSW_changeClip(itemIndex) {
    index = itemIndex;
    if (isChanging == false) {
        if ($("#itemRep_" + index + "> .itemID").text() != $(".movieID").text()) {
        isChanging = true;
        $(".vidWrapper").fadeTo(900, 0.01);//fade all vids
        setTimeout("GSW_UpdateClipDetails()", 1000);
        }
    }
}

//updates all the fields to do with the clip
function GSW_UpdateClipDetails() {
    $(".movieDescription").text($("#itemRep_" + index + "> .itemDesc").text());
    $(".movieMainTitle").text($("#itemRep_" + index + "> .movieTitle").text());
    $(".movieID").text($("#itemRep_" + index + "> .itemID").text());
    $("#itemRep_" + index + " > #vidWrapper").fadeTo(2000, 1);//show only the one selected
    setTimeout("GSW_PreventChangingVidWhileLoading()", 1000);
}

function GSW_PreventChangingVidWhileLoading(){
    isChanging = false;
}
*/
//feature II


function GSW_FeatureII(){
    

    var x = 0;


    $("#FeatureIIWrapper").hover(
          function() {

              $('#CycleWrapper').cycle('pause');
              $(".featureNav").fadeIn(300);
          },
          function() {
              $('#CycleWrapper').cycle('resume');
              $(".featureNav").fadeOut(300);
          }
    );
}


/*


// Checks if an event happened on an element within another element
// Used in jQuery.event.special.mouseenter and mouseleave handlers
var withinElement = function(event) {
    // Check if mouse(over|out) are still within the same parent element
    var parent = event.relatedTarget;
    // Traverse up the tree
    while (parent && parent != this)
        try { parent = parent.parentNode; }
    catch (e) { parent = this; }

    if (parent != this) {
        // set the correct event type
        event.type = event.data;
        // handle event if we actually just moused on to a non sub-element
        jQuery.event.handle.apply(this, arguments);
    }
};

jQuery.each({
    mouseover: 'mouseenter',
    mouseout: 'mouseleave'
}, function(orig, fix) {
    jQuery.event.special[fix] = {
        setup: function() {
            jQuery.event.add(this, orig, withinElement, fix);
        },
        teardown: function() {
            jQuery.event.remove(this, orig, withinElement);
        }
    };
});

jQuery.each(("blur,focus,load,resize,scroll,unload,click,dblclick," +
	"mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave," +
	"change,select,submit,keydown,keypress,keyup,error").split(","), function(i, name) {

	    // Handle event binding
	    jQuery.fn[name] = function(fn) {
	        return fn ? this.bind(name, fn) : this.trigger(name);
	    };
	});
	
	*/




function GSWSubmitForm(url,btn) {
    
    if (btn) {
        $('#aspnetForm').attr('action', url).attr('target','_blank');
        btn.click();
    }
    else {
        $('#aspnetForm').attr('action', url).attr('target', '_blank').submit();
    }
    
    
   
} 