﻿//// MENU SLIDEY BIT /////
     (function($) {
	if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8
		var oldCurCSS = jQuery.curCSS;
		jQuery.curCSS = function(elem, name, force){
			if(name === 'background-position'){
				name = 'backgroundPosition';
			}
			if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style && style[ name ] ){
				return style[ name ];
			}
			return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
		};
	}
	
	var oldAnim = $.fn.animate;
	$.fn.animate = function(prop){
		if('background-position' in prop){
			prop.backgroundPosition = prop['background-position'];
			delete prop['background-position'];
		}
		if('backgroundPosition' in prop){
			prop.backgroundPosition = '('+ prop.backgroundPosition;
		}
		return oldAnim.apply(this, arguments);
	};
	
	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}
	
	$.fx.step. backgroundPosition = function(fx) {
		if (!fx.bgPosReady) {
			var start = $.curCSS(fx.elem,'backgroundPosition');
			
			if(!start){//FF2 no inline-style fallback
				start = '0px 0px';
			}
			
			start = toArray(start);
			
			fx.start = [start[0],start[2]];
			
			var end = toArray(fx.options.curAnim.backgroundPosition);
			fx.end = [end[0],end[2]];
			
			fx.unit = [end[1],end[3]];
			fx.bgPosReady = true;
		}
		//return;
		var nowPosX = [];
		nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
		nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
		fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

	};
})(jQuery);
///////////////////////////////////////

////// Loading Page function /////////
var page = 0;
function currentPage(num)
    {
        page = num;
        switch(page)
        {
            case 1:    
                $("#home_nav").css("background-position","0px 128px");                                   
                break;
            case 2:            
                $("#concept_nav").css("background-position","0px 128px");                
                break;
            case 3:           
                $("#company_nav").css("background-position","0px 128px");
                break;
            case 4:           
                $("#offices_nav").css("background-position","0px 128px");
                break;
            case 5:            
                $("#partners_nav").css("background-position","0px 128px");
                break;
            case 6:          
                $("#newsandpress_nav").css("background-position","0px 128px");
                break;
            case 7:           
                $("#jobs_nav").css("background-position","0px 128px");
                break;
            case 8:            
                $("#home_nav").css("background-position","0px 128px");
                break;
            default:;
                break;
        }   
    }   

//////////////////////////////////////

    $(document).ready(function() {

        if(page != 8)
        {
            sameHeightDivs("#sopLeft", ".sopNavRight");
        }
  
        function sameHeightDivs(divOne, divTwo) {
            var divOneHeight = $(divOne).height();
            var divTwoHeight = $(divTwo).height();            
            if (divOneHeight > divTwoHeight) {
                $(divTwo).height(divOneHeight+20);
            }
            else {
                $(divOne).height(divTwoHeight-20);
            }            
        }

        $("input").focus(function() {
            $(this).css('border', 'solid 1px Orange');
        });
        $("input").blur(function() {
            $(this).css('border', 'solid 1px Gray');
        });

        /************* FANCY BOX STUFF *************/
        //$(".TermsCond label").fancybox({ 'hideOnContentClick': true });
        $("#inline").fancybox({ 'hideOnContentClick': true });

        $(".shopLightbox").fancybox({ 'hideOnContentClick': true, 'overlayOpacity': 0.75, 'frameWidth': 800, 'frameHeight': 500 });
        $(".myMoneyLightBox").fancybox({ 'hideOnContentClick': true, 'overlayOpacity': 0.75, 'frameWidth': 700, 'frameHeight': 750 });         
        $("a.group").fancybox({ 'hideOnContentClick': false });


        $("#slideCheckClick").click(function() {

            if ($("#slideFree").is(":hidden")) {
                $("#slideFree").slideDown("slow");
            } else {
                $("#slideFree").slideUp("slow");
            }
        });
        $("#slideCheckClick2").click(function() {

            if ($("#slideCost").is(":hidden")) {
                $("#slideCost").slideDown("slow");
            } else {
                $("#slideCost").slideUp("slow");
            }
        });

        $("#staffContent").fadeOut(0); $("#staffContent").html($("#staff1").html()); $("#staffContent").fadeIn("slow");
        $(".staff1").click(function() { $("#staffContent").fadeOut(0); $("#staffContent").html($("#staff1").html()); $("#staffContent").fadeIn("slow"); });
        $(".staff2").click(function() { $("#staffContent").fadeOut(0); $("#staffContent").html($("#staff2").html()); $("#staffContent").fadeIn("slow"); });
        $(".staff3").click(function() { $("#staffContent").fadeOut(0); $("#staffContent").html($("#staff3").html()); $("#staffContent").fadeIn("slow"); });
        $(".staff4").click(function() { $("#staffContent").fadeOut(0); $("#staffContent").html($("#staff4").html()); $("#staffContent").fadeIn("slow"); });
        $(".staff5").click(function() { $("#staffContent").fadeOut(0); $("#staffContent").html($("#staff5").html()); $("#staffContent").fadeIn("slow"); });

    });

$(document).ready(function() {
	
	// Expand Panel
	$("#open").click(function(){
		$("div#panel").slideDown("slow");
	
	});	
	
	// Collapse Panel
	$("#close").click(function(){
		$("div#panel").slideUp("slow");	
	});		
	
	// Switch buttons from "Log In | Register" to "Close Panel" on click
	$("#toggle a").click(function () {
		$("#toggle a").toggle();
	});

});

function checkValidation() {
    var BankAccName = document.getElementById("StoreBankAccountName");
    var Postcode = document.getElementById("StorePostcode");
    var PhoneNum = document.getElementById("StorePhoneNumber");
    var SortCode = document.getElementById("StoreBankSortCode");
    var NameBank = document.getElementById("StoreBankName");
    var OwnerName = document.getElementById("StoreOwnerName");
    var BankAccNum = document.getElementById("StoreBankAccountNumber");

    if (
        (PhoneNum.value == "") ||
        (Postcode.value == "") ||
        (OwnerName.value == "")      
        ) 
    {
        if (PhoneNum.value == "") { $("#StorePhoneNumber").addClass("redStyleInput"); }
        if (Postcode.value == "") { $("#StorePostcode").addClass("redStyleInput"); }
        if (OwnerName.value == "") { $("#StoreOwnerName").addClass("redStyleInput"); }
        
        alert("Please enter all required information");
        return false;
    }
    else
    {
        return true;
    }
    
    return true;
}

function checkBuy() {
    return confirm("Are you sure you want to purchase this product?");
}
