// Popup window code
function newPopup(url) {
	popupWindow = window.open(
		url,'popUpWindow','height=500,width=400,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=no')
}


function doSomething(e) {
    //alert('here');
    if (!e) var e = window.event;
    
    var tg = (window.event) ? e.srcElement : e.target;
    //alert ('1');
    if (tg.id != 'shopping-bag-contents' || 'shopping-bag' || ''){
        shoppingCartShrink();
        return;
    }
    //alert (tg.id);
    // Mouseout took place when mouse actually left layer
    //alert('left div');
}

function copyOverValues() {

    document.pay.deliveryFirstName.value = document.pay.billingFirstName.value;
    document.pay.deliverySurname.value = document.pay.billingSurname.value;
    document.pay.deliveryAddress1.value = document.pay.billingAddress1.value;
    document.pay.deliveryAddress2.value = document.pay.billingAddress2.value;
    document.pay.deliveryCity.value = document.pay.billingCity.value;
    document.pay.deliveryPostcode.value = document.pay.billingPostcode.value;

}

//needs jquery to operate

function slideDown(ID,list,shrink){

    expand = document.getElementById(list).offsetHeight;

    var listControl = document.getElementById(list);
    var countItems = listControl.getElementsByTagName('li').length;

    //alert(countItems);
    expand = countItems * 25 + 30;

    if(document.getElementById(ID).offsetHeight < 60)
    {
      document.getElementById(ID+'-arrow').src = "http://www.vicky-martin.com/view/images/arrowdown.jpg";
      document.getElementById(ID+'-arrow').style.marginTop ='5px';
      $("#"+ID).animate({
        height: expand
      }, 1500 );
      

    }else{
        document.getElementById(ID+'-arrow').src = "http://www.vicky-martin.com/view/images/arrow.jpg";
        document.getElementById(ID+'-arrow').style.marginTop ='3px';
        $("#"+ID).animate({
        height: shrink
      }, 1500 );
      
    }

}

function showPic(bigpic,smallpic){
    document.getElementById('mainpic-image').src = smallpic;
    document.getElementById('mainpic-link').href = bigpic;
}

function shoppingCartExpand(){
    x = document.getElementById('shopping-bag');
    
    height = document.getElementById('shopping-list').offsetHeight;
    if(height > 0){
        height = height + 90;
    }else{
        height = 30;
    }
    if(x.offsetHeight == 30){
        $("#shopping-bag").animate({
            height: height +'px'
          }, 500 );
    }
}

function shoppingCartShrink(){
    x = document.getElementById('shopping-bag');

    if(x.offsetHeight > 30){
        $("#shopping-bag").animate({
            height: '30px'
          }, 500 );
    }

    return false;
} 
