﻿function GetRootUrl(){
	var pathparts = document.location.pathname.split('/');
	var url = 'http://' + document.location.hostname;
	return url;
}
function registerjs(){

	if(typeof(WPSC) == "undefined"){

		WPSC = new Object();
		WPSC.Init = function(){
		//do nothing
		}
		WPSC.WebPartPage = new Object();
		WPSC.WebPartPage.Parts = new Object();
		WPSC.WebPartPage.Parts.Register = function()
		{
		//do nothing
		}
	}
}
function querylist(listname, soapenv, response){		

	if(!soapenv){
		var soapenv = "\
		<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
			<soapenv:Body> \
				 <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
					<listName>" + listname + "</listName> \
					<viewFields> \
						<ViewFields> \
						</ViewFields> \
					</viewFields> \
				</GetListItems> \
			</soapenv:Body> \
		</soapenv:Envelope>";
	}

	if(!response){
		response = 'raw';
	}	
 	// Do the web service call async.
 	
	var xmlDoc = $.ajax({
		url: GetRootUrl() + "/_vti_bin/lists.asmx",
	    type: "POST",
	    dataType: "xml",
	    data: soapenv,
	    async: false,
	    contentType: "text/xml; charset=\"utf-8\""
	});

	if(response == 'text'){
		return xmlDoc.responseText;
	}
	
	if(response == 'array'){
		var rows = new Array(); var c = 0;
		$(xmlDoc.responseXML).find("z\\:row").each(function() {
			rows[c] = $(this);
			c=(c*1)+1;
		});
		
		return rows;
	}
	
	if(response == 'raw'){
		
		return xmlDoc;
	}	
}
function hide_login(domain){

	var href = window.location.href;
	href = href.replace('http://', '').replace('www.', '');
	href_array = href.split('/');
	href = href_array[0];

	if(href == domain){		
		$('#ctl00_explitLogout_ExplicitLogin').hide();
	}
}
function next_banner(max){
	
	var id = ($('#image-show-id').text()*1);
	
	if(id > max) id = 1;
	
	var url = $('#image-show-data-'+id+' .url').text();
	var alt = $('#image-show-data-'+id+' .alt').text();

	$('#image-show-id').text(id+1);	
	$('#slide-show-image').attr({'src':url,'alt':alt,'title':alt})
	$('#caption').text(alt);

};
function click_clear(obj, default_string){

	if($(obj).val() == default_string){
		$(obj).val("")
	}else if($(obj).val().length == 0){
		$(obj).val(default_string)
	}
}
$(function() {

	$('#site-search-input').keypress(function(event) {
		if (event.which == '13') {
			event.preventDefault();
			window.location = GetRootUrl()+ '/Pages/search-results.aspx?k=' + $(this).val();
		}
	});
    var imageRotator =
    {
        init: function()
        {
            //initial fade-in time (in milliseconds)
            var initialFadeIn = 600;
 
            //interval between items (in milliseconds)
            var itemInterval = 5000;
 
            //cross-fade time (in milliseconds)
            var fadeTime = 2500;
 
            //count number of items
            var numberOfItems = $('div.image').length;
 
            //set current item
            var currentItem = 0;
 
            //show first item
            $('div.image').eq(currentItem).fadeIn(initialFadeIn);
 
            //loop through the items
            var infiniteLoop = setInterval(function(){
                $('div.image').eq(currentItem).fadeOut(fadeTime);
 
                if(currentItem == numberOfItems -1){
                    currentItem = 0;
                }else{
                    currentItem++;
                }
                $('div.image').eq(currentItem).fadeIn(fadeTime);
 
            }, itemInterval);
        }
    };
 
    imageRotator.init();


	hide_login('ourfuturevb.com');
	$('.ms-WPBody').removeClass('ms-WPBody');

// Image Shadow wrap
	$('.wrap-shadow').each(function () {
		$(this).wrap(
		'<span class="shadow-wrap"><span><span><span><span></span></span></span></span></span>');
		var caption = $(this).attr("alt");
		var width = $(this).attr("width");
		if(caption.length>0){
		$(this).css("border-bottom","0");
		$(this).after('<span id="caption" class="img-caption" style="width: 290px; border: 0;">' + caption +'</span>');
		}
	});
	registerjs();

});
if(typeof(SendSoap) == 'undefined'){
	function SendSoap(x, y, z){
	}
}

