
function openPopup(url, w, h) {
    width = w;
    height = h;
    x = parseInt(screen.width / 2.0) - (width / 2.0);
    y = parseInt(screen.height / 2.0) - (height / 2.0);

    var win = window.open(url, "editorPopup", "top=" + y + ",left=" + x + ",scrollbars=no,dialog=yes,minimizable=no,modal=yes,width=" + width + ",height=" + height + ",resizable=no");
}

function deleteZoneContent(ZoneAreaVal, PageIDVal) {

    $.ajax({
        type: "POST",
        url: "/admin/DeleteContent.asmx/DeleteZone",
        data: "{'ZoneArea': " + ZoneAreaVal + ", 'PageID': " + PageIDVal + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            alert("Content has been removed from this area.");
            window.location.reload(true);
        }
    });

}

function disableEnterKey(e) {
    var key;
    if (window.event)
        key = window.event.keyCode; //IE
    else
        key = e.which; //firefox     

    return (key != 13);
}

function OnComplete(args) {
    alert(args);
}

function OnTimeOut(args) {
    alert("ERROR : Service call timed out. Possbily content area has no content.");

}

function OnError(args) {
    alert("Error calling service method.");
}

function hideAjax() {
    jQuery("#display").hide();
}

function fillSearch(prodTitle) {
    document.getElementById("ctl00_searchBox").value = prodTitle;
    document.getElementById("ctl00_searchBox").disabled = true;
}

jQuery(document).ready(function () {
    var tabContainers = jQuery('div.tabs > div');
    tabContainers.hide().filter(':first').show();

    jQuery('div.tabs ul.tab-navigation a').click(function () {
        tabContainers.hide();
        tabContainers.removeClass('on');
        tabContainers.filter(this.hash).show();
        jQuery('div.tabs ul.tab-navigation li').removeClass('on');
        jQuery(this).parent().addClass('on');
        tabContainers.filter(this.hash).addClass("on");
        return false;
    }).filter(':first').click();
});

jQuery(document).ready(function () {
    var tabContainers = jQuery('div.tabs2 > div');
    tabContainers.hide().filter(':first').show();

    jQuery('div.tabs2 ul.tab-navigation2 a').click(function () {
        tabContainers.hide();
        tabContainers.removeClass('on');
        tabContainers.filter(this.hash).show();
        jQuery('div.tabs ul.tab-navigation2 li').removeClass('on');
        jQuery(this).parent().addClass('on');
        tabContainers.filter(this.hash).addClass("on");
        return false;
    }).filter(':first').click();
});

jQuery(document).ready(function () {

	$("ul.mainMenu li.on ul.subMenu").show();

	
	$("ul.mainMenu").hover(function () {
	    $("ul.mainMenu li").hover(function () { //Hover over event on list item
			$("ul.mainMenu li.on ul.subMenu").hide();
	        $(this).find(".subMenu").show(); //Show the subnav
	    }, function () { //on hover out...
	        $(this).find(".subMenu").hide(); //Hide the subnav
	    });
	}, function () {
		$("ul.mainMenu li.on ul.subMenu").show();
	});
	
	$("ul.SubPageImage li:nth-child(3n)").addClass("last");
	$("ul.SubPageImage1 li:nth-child(3n)").addClass("last");
	$("ul.SubPageImage2 li:nth-child(3n)").addClass("last");

});

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

// Advert details image
function DetailsImageRoll(ImageURL)
{
	document['DetailsImageMain'].src = ImageURL;
}

function DetailsImageRollOut(ImageURL)
{
	document['DetailsImageMain'].src = ImageURL;
}

$(document).ready(function () {
    //Examples of how to assign the ColorBox event to elements
    $("a[rel='adgallery']").colorbox();
    $("a[rel='advertgallery']").colorbox({scalePhotos: true, maxWidth:800, maxHeight: 600});
	$("a[rel='advertgallery2']").colorbox({scalePhotos: true, maxWidth:800, maxHeight: 600});
    //Random JQuery
    $("ul.SubPageImage li:nth-child(3n)").addClass("last")
    $("#homeImage ul#homeImageSecond li:nth-child(3n)").addClass("last")
    $("#wrapper #left-col #nearbydrivers ul#nearbydriverslink li:nth-child(4n)").addClass("last")
	$("#NearbyPlaces div:nth-child(4n)").addClass("last")
	$("div#menu ul.mainMenu li:last-child").addClass("last");
	$("div#homemenu ul li:nth-child(2n)").addClass("alt");
	$("div#drivers ul li:nth-child(4n)").addClass("last");
	$("div#right-col ul.rightMenu li:nth-child(2n)").addClass("alt");
	$("ul#footerMenu li:last-child").addClass("last");
});

function StreetView() {
	$("div#Location_map").hide()
	$("div#Street_view").show()
}

function MapView() {
	$("div#Street_view").hide()
	$("div#Location_map").show()
}

/* Search Panel JS */
var _updateProgressDiv;
var _backgroundDiv;
var _gridView;

function pageLoad(sender, args) {
    with (Sys.WebForms.PageRequestManager.getInstance()) {
        add_beginRequest(beginRequest);
    }
}

function beginRequest(sender, args) {
    jQuery(".TownDDL").attr("disabled", "disabled");
}

function onUpdating() {
    // get the update progress div
    var updateProgressDiv = $get('updateProgressDiv');
    // make it visible
    updateProgressDiv.style.display = '';

    //  get the gridview element        
    var gridView = $get('SearchDDs');

    // get the bounds of both the gridview and the progress div
    var gridViewBounds = Sys.UI.DomElement.getBounds(gridView);
    var updateProgressDivBounds = Sys.UI.DomElement.getBounds(updateProgressDiv);

    //    do the math to figure out where to position the element (the center of the gridview)
    var x = gridViewBounds.x + Math.round(gridViewBounds.width / 2) - Math.round(updateProgressDivBounds.width / 2);
    var y = gridViewBounds.y + Math.round(gridViewBounds.height / 2) - Math.round(updateProgressDivBounds.height / 2);

    //    set the progress element to this position
    Sys.UI.DomElement.setLocation(updateProgressDiv, x, y);
}

function onUpdated() {
    // get the update progress div
    var updateProgressDiv = $get('updateProgressDiv');
    // make it invisible
    updateProgressDiv.style.display = 'none';
}


function clearboxes() {
    $("div.AdvancedSearch div.sliderpanel input").attr('checked', false);
}

function filterboxes()
{
    $("div.AdvancedSearch div.sliderpanel > div").hide();

	if ($(".TypeDDL").val() != "")
	{
	    $("div.AdvancedSearch div.sliderpanel > div.Filter" + $(".TypeDDL").val()).show();
	    //$("div.AdvancedSearch div.sliderpanel > div#ctl00_ContentPlaceHolder1_ctl00_acc" + $(".TypeDDL").val()).show();
	    
	}
	else
	{
		var FilterStr = "";
		$(".TypeDDL > option").each(function(){
			if (this.value > 0) {
				FilterStr += ".Filter" + this.value
			}			
		});
		//alert("$("+FilterStr+").show();");
		$(FilterStr).show();
	}
}

/* Advanced Search Filters */
$(document).ready(function () {
    $("div.AdvancedSearch div.sliderpanel > div").hide();
    $("div.sliderpanel").show();
	filterboxes();
});

/* Tab Panels */
$(document).ready(function () {
	$("div#advert-details div#tabs").show();

	var mystr = $("div#advert-details div#tabs div#tabs-2").html();
	if (mystr) {
	if (mystr.indexOf("<") < 0)
	{
		$("div#advert-details div#tabs li#tablink2").hide();
	}
	}
	
	var mystr = $("div#advert-details div#tabs div#tabs-3").html();
	if (mystr) {
	if (mystr.indexOf("<") < 0)
	{
		$("div#advert-details div#tabs li#tablink3").hide();
	}
	}
	//$("div#advert-details div#tabs div#tabs-4").hide();
});

function hidemap()
{
	$("div#advert-details div#tabs div#tabs-4").css({position: 'absolute', left: '-100000px'});
}

function showmap()
{
	$("div#advert-details div#tabs div#tabs-4").css({position: 'relative', left: '0px'});
}

/* Breadcrumb */
$(document).ready(function () {
    $("div#pages-breadcrumb a:last-child").addClass("last");
    $('a.mapPopup').colorbox({ href: "/wherearewe.aspx", width: 740, height: 550, iframe: true, title: "Exmoor", scrolling: false });
    $('#fontresize>li:first').fontresizing();
	$("#footerMenu li:nth-child(3n) a").attr('target', '_blank');
	$("#footerMenu li:nth-child(6n) a").attr('target', '_self');
});

function checkslide()
{
	if ($("#pageslider > img").size() > 1)
	{
		 $('#pageslider').nivoSlider({
            effect: 'fade',
            controlNav: false,
            directionNavHide: true,
            manualAdvance: false,
            prevText: '',
            nextText: ''
        });
	} else if ($("#pageslider > img").size() == 1) {
		$('#pageslider').nivoSlider({
            effect: 'fade',
            controlNav: false,
            directionNavHide: true,
            manualAdvance: true,
            prevText: '',
            nextText: ''
        });
	}
	$('.nivo-control.active').css('display', 'none');
	$('.nivo-prevNav').css('display', 'none');
	$('.nivo-nextNav').css('display', 'none');
}
