function removeSpaces(string){
	form.postcode = string.split(' ').join('');
}

function findPos(obj) {
	var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {
                curleft += obj.offsetLeft;
                curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
	return [curleft,curtop];
}


var root = "http://uidget.appspot.com/hbos/";
//var root = "http://10.1.1.63:8080/hbos/";

jQuery(function(){

    var curpos = findPos(document.getElementById('root_hbos_314'));

    jQuery('#get_widget_314').css('left',String(-curpos[0]));
    jQuery('#get_widget_314').css('top',String(-curpos[1]));


    jQuery('.get_widget_314').click(function(){
        jQuery('#get_widget_314').show();
    });
    jQuery('#get_widget_close_314').click(function(){
        jQuery('#get_widget_314').hide();
    });

    jQuery('.go_postcode').click(function(){
        var pcode = String(document.postcode_form.postcode.value).split(' ').join('');
        var referurl = "http://www.multimap.com/clients/browse.cgi?client=halifax&client=halifax&addr2=&types=BRANCH&db=GB&reclimit=15&addr3=&pc=" + pcode;
        jQuery('.go_postcode').attr('href',referurl);
        return true;
    });
    
	jQuery('.more_info').click(function(){
		if(jQuery('.switch_314').hasClass('more_info')){
			resetPage2Header();
			jQuery('.root_hbos_314').css('background-image','none');
			jQuery('.root_hbos_314').css('background-color','#C5C4BF');
			jQuery('.bottom_hbos_314').css('background-color','#ECF1F6');
			jQuery('.content_hbos_314').css('background-color','#ECF1F6');
			jQuery('.visit_halifax').css('background-image','url(' + root + 'static/visit_halifax.jpg)');
			jQuery('.content1_hbos_314').hide("fast");
			jQuery('.content2_hbos_314').show("fast");
			jQuery('.switch_314').removeClass('more_info');
			jQuery('.switch_314').addClass('less_info');
			jQuery('.savings_nav_314').addClass('nav2_show_314');
			jQuery('.page1_hbos_314').addClass('page2_show_314');
			jQuery('.page2_show_314').show("fast");
		}
		else{
			jQuery('.content2_hbos_314').hide("fast");
			jQuery('.savings_nav_314').removeClass('nav2_show_314');
			jQuery('.page2_show_314').hide("fast");
			jQuery('.page2_show_314').removeClass('page2_show_314');
			jQuery('.content1_hbos_314').show("fast");
			jQuery('.root_hbos_314').css('background-color','transparent');
			jQuery('.root_hbos_314').css('background-image','url(' + root + 'static/background.jpg)');
			jQuery('.visit_halifax').css('background-image','url(' + root + 'static/visit_halifax1.jpg)');
			jQuery('.root_hbos_314').css('background-repeat','no-repeat');
			jQuery('.bottom_hbos_314').css('background-color','transparent');
			jQuery('.content_hbos_314').css('background-color','transparent');		

			jQuery('.switch_314').removeClass('less_info');
			jQuery('.switch_314').addClass('more_info');
		}
		return false;
	});

	jQuery('.savings_nav_314').click(function(){
		if(!jQuery('.savings_nav_314').hasClass('nav2_show_314')){
			jQuery('.page2_show_314').hide("fast");
			jQuery('.page2_show_314').removeClass("page2_show_314");
			//removeBold();
			jQuery('.nav2_show_314').removeClass("nav2_show_314");
			jQuery('.savings_nav_314').addClass('nav2_show_314');
			//addBold();
			jQuery('.page1_hbos_314').addClass('page2_show_314');
            setNormal();
            jQuery('.savings_normal_314').hide();
            jQuery('.savings_bold_314').show();
			jQuery('.page2_show_314').show("fast");
		}
		return false;
	});
	jQuery('.money_nav_314').click(function(){
		if(!jQuery('.money_nav_314').hasClass('nav2_show_314')){
			jQuery('.page2_show_314').hide("fast");
			jQuery('.page2_show_314').removeClass("page2_show_314");
			//removeBold();
			jQuery('.nav2_show_314').removeClass("nav2_show_314");
			jQuery('.money_nav_314').addClass('nav2_show_314');
			//addBold();
			jQuery('.page2_hbos_314').addClass('page2_show_314');
            setNormal();
            jQuery('.money_normal_314').hide();
            jQuery('.money_bold_314').show();
			jQuery('.page2_show_314').show("fast");
		
		}
		return false;
	});
	jQuery('.interest_nav_314').click(function(){
		if(!jQuery('.interest_nav_314').hasClass('nav2_show_314')){
			jQuery('.page2_show_314').hide("fast");
			jQuery('.page2_show_314').removeClass("page2_show_314");
			//removeBold();
			jQuery('.nav2_show_314').removeClass("nav2_show_314");
			jQuery('.interest_nav_314').addClass('nav2_show_314');
			//addBold();
			jQuery('.page3_hbos_314').addClass('page2_show_314');
            setNormal();
            jQuery('.interest_normal_314').hide();
            jQuery('.interest_bold_314').show();
			jQuery('.page2_show_314').show("fast");
		
		}
		return false;
	});
	jQuery('.isas_nav_314').click(function(){
		if(!jQuery('.isas_nav_314').hasClass('nav2_show_314')){
			jQuery('.page2_show_314').hide("fast");
			jQuery('.page2_show_314').removeClass("page2_show_314");
			//removeBold();
			jQuery('.nav2_show_314').removeClass("nav2_show_314");
			jQuery('.isas_nav_314').addClass('nav2_show_314');
			//addBold();
			jQuery('.page4_hbos_314').addClass('page2_show_314');
            setNormal();
            jQuery('.isas_normal_314').hide();
            jQuery('.isas_bold_314').show();
			jQuery('.page2_show_314').show("fast");
		
		}
		return false;
	});
	
	function removeBold(){
		var boldurl = jQuery('.nav2_show_314').css('background-image');
		var newurl = boldurl.replace('_bold','_normal');
		jQuery('.nav2_show_314').css('background-image',newurl);
		return false;
	}
	function addBold(){
		var boldurl = jQuery('.nav2_show_314').css('background-image');
		var newurl = boldurl.replace('_normal','_bold');
		jQuery('.nav2_show_314').css('background-image',newurl);
		return false;
	}

    function setNormal(){
        jQuery('.savings_normal_314').show();
        jQuery('.savings_bold_314').hide();
        jQuery('.money_normal_314').show();
        jQuery('.money_bold_314').hide();
        jQuery('.interest_normal_314').show();
        jQuery('.interest_bold_314').hide();
        jQuery('.isas_normal_314').show();
        jQuery('.isas_bold_314').hide();
    }
    
	function resetPage2Header(){
		var url1 = jQuery('.savings_nav_314').css('background-image');
		if(url1.indexOf('_normal')!=-1){
			jQuery('.savings_nav_314').css('background-image',url1.replace('_normal','_bold'));
		}
		var url2 = jQuery('.money_nav_314').css('background-image');
		if(url2.indexOf('_bold')!=-1){
			jQuery('.money_nav_314').css('background-image',url2.replace('_bold','_normal'));
		}
		var url3 = jQuery('.interest_nav_314').css('background-image');
		if(url3.indexOf('_bold')!=-1){
			jQuery('.interest_nav_314').css('background-image',url3.replace('_bold','_normal'));
		}
		var url4 = jQuery('.isas_nav_314').css('background-image');
		if(url4.indexOf('_bold')!=-1){
			jQuery('.isas_nav_314').css('background-image',url4.replace('_bold','_normal'));
		}
        setNormal();
        jQuery('.savings_normal_314').hide();
        jQuery('.savings_bold_314').show();
		return false;
	}
	
});
