﻿/// <reference path="intellisense/jquery-1.3.2-vsdoc2.js" />


$(function() {

    InitiliazeSiteCommon();
    $.getScript = function(url, callback, cache) { $.ajax({ type: "GET", url: url, success: callback, dataType: "script", cache: cache }) };

    $.getScript('/script/jquery.blockUI.js', function() { $().ajaxStart($.blockUI).ajaxStop($.unblockUI); }, true);

    $.getScript('/script/json2.js', SetSiteObjects(), true);

	       
$(".anchorlink").click(function(event){
	        //prevent the default action for the click event
	        event.preventDefault();	
	        //get the full url - like mysitecom/index.htm#home
	        var full_url = this.href;	 
	        //split the url by # and get the anchor target name - home in mysitecom/index.htm#home
	        var parts = full_url.split("#");
	        var trgt = parts[1]; 
	        //get the top offset of the target anchor
	        var target_offset = $("#"+trgt).offset();
	        var target_top = target_offset.top;	 
	        //goto that anchor by setting the body scroll top to anchor top
	        $('html, body').animate({scrollTop:target_top}, 'slow');		
			return false;
	    });

});




function InitiliazeSiteCommon() {

	
    $('a[rel="external"]').click(function() {
        window.open($(this).attr('href'));
        return false;
    });

    $("#myscroll").mbScrollable({
        dir: "vertical",
        width: 725,
        height: 19,
        elementsInPage: 1,
        elementMargin: 1,
        shadow: false,                 // shadow:"2px 2px 2px 2px",
        controls: "#controls1",
        slideTimer: 500,
        autoscroll: true,
        scrollTimer: 5000
    });

    $(".stop").click(function() { $(this).toggleClass("none"); $(".start").toggleClass("none"); });
    $(".start").click(function() { $(this).toggleClass("none"); $(".stop").toggleClass("none"); });
    
       $("#newsfeed").click(function() { 
        if ($('#myscroll').hasClass('domainnews'))
        {
            //which link is displayed when newsfeed is clicked?
            var style = $('.scrollableStrip').attr('style');
            var position = 0;
            if (style != '' && style.indexOf('margin-top:',0) > 0)
            {
                var startpos = style.indexOf('margin-top:',0);
                style = jQuery.trim(style.substring(startpos+11, style.indexOf('px;',startpos)));
                position = Math.abs(parseInt(style/19));
            }
            var url = $('.SECont:eq(' + position + ') .scrollEl a').attr('href');

            if (url != null)
            {
		url = String(window.location);
		var urlArray=url.split("/");
		//url = url.substring(0,url.indexOf('http://www.goodmanbusinessparks.co.uk/'));
               //alert(urlArray[0]+urlArray[1]+urlArray[2]);
		url=urlArray[0]+urlArray[1]+urlArray[2];
		if (url=='http:www.goodmanbusinessparks.co.uk') 
		{
		window.location = 'http://www.goodmanbusinessparks.co.uk/the-parks/news-feeds.html';
		}
		else window.location = 'http://www.goodmanlogistics.co.uk/welcome/news-feeds.html';
            }
        }
        else window.location = '/news.rss';
    });
    
}
function SetSiteObjects() {



    $(".menudl a[href^='http:']:not([href*='" + window.location.host + "'])").live('click', function(evt) {
        evt.preventDefault();
        if (!$(this).hasClass('.active')) {
            var dictionary = { "ObjectURL": $(this).attr('href')};
//            alert($(this).attr('href'));
//            alert($(this));
//            alert($(this).html());
            GetSiteObject(dictionary, $(this))
        }
        return false;
    });
}

function GetSiteObject(dictionary, menuitem) {

    var query = {};
    // var dic = { "WebPartId": partId, "Caller": callerId, "Action": actionId };



    //alert($(menuitem).parent().html());
    $('dl.active').find('a.active').removeClass('active');
    $(menuitem).removeClass('active').addClass('active');



    
    query.dic = dictionary;
    $.ajax({
        type: "POST",
        url: "/errors.aspx/getsiteobject",
        data: JSON.stringify(query),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(obj) {
        ChangePageTitle($(menuitem).html());

            $(obj).each(function() {
                var content = this.PartContent;
                //alert(this.PartContent);
                //alert(this.toString());
                eval(this.Scripts[0].toString());


            });
        }
    });
}

function ChangePageTitle(newtitle) {

    document.title = newtitle + document.title.substring(document.title.lastIndexOf(":") - 1);
}

