// JScript File

var menu_on = false;

$(document).ready(function () { 
	
	if ($('body').hasClass('nodeid-1318'))  $('body').removeClass('sidebar-left');
	
	var hidemenu = function(){
     if(!menu_on){
	  var m = $("li.menu-region a");
	  m.removeClass("selected");
	  var fs = $("#flagselection");
	  fs.hide(); // SAFARI
	  //fs.css('display','none');
	 }
	};
	
	$('li.menu-region a').hover(function() {
	  menu_on = true;
	  var m = $("li.menu-region a");
	  m.addClass("selected");
	  var fs = $("#flagselection");
	  
	  var o = m.offset({scroll: false});
	
      fs.css('top',(o.top + 29) + 'px');
	  fs.css('left',o.left + 'px');
	  fs.show();
	  //fs.css('display','');
	}, function() {
	  menu_on = false;
	  setTimeout(function() { hidemenu(); }, 1000);
	});
	
	$('#flagselection').hover(function() {
	   menu_on = true;
	}, function() {
	  /*
	  var m = $("li.menu-region a");
	  m.removeClass("selected");
	  var fs = $("#flagselection");
	  fs.hide(); */
	  menu_on = false;
	  setTimeout(function() { hidemenu(); }, 500);
	}); 	
	

	   var region = 'uk';
     if (0 <= document.cookie.indexOf('ak_region=us')) region = 'us';
     if (0 <= document.cookie.indexOf('ak_region=au')) region = 'au';
     $('li#setregion' + region + ' a').addClass('active'); 
     $('body').addClass('region_' + region);

	   if ($('div.homepage').length) {


  /*   
      var script = document.createElement('script');
      script.type = 'text/javascript';
      script.src = '/JavaScript/jcarousel/lib/jquery.jcarousel.js';
      document.getElementsByTagName('head')[0].appendChild(script);

 */
     $('div.featurewidget').append('<ul id="widgetnavbar"><li id="button1"><a href="#">Baby</a></li><li id="button2"><a href="#">Toddler</a></li><li id="button3"><a href="#">Kids</a></li><li id="button4"><a href="#">For Mum</a></li></ul>');
     
     jQuery('ul#carousel').jcarousel({
        initCallback: mycarousel_initCallback,
        wrap: 'last'
    });
    jQuery('ul#carousel').parent().css('width','672px'); //ie6 sux
 //   jQuery('div.featurewidget div.jcarousel-container').hide();
    $('div.featurewidget').css('visibility','visible');
    $('ul#carousel li').cycle({
		   fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		   timeout:  3000
	  });
    // 
   }
	
	
});



function mycarousel_initCallback(carousel) {
    $('li#button1 a').click(function() { carousel.scroll(2); $('ul#widgetnavbar li a').removeClass('active'); $(this).addClass('active'); return false; });
    $('li#button2 a').click(function() { carousel.scroll(3); $('ul#widgetnavbar li a').removeClass('active'); $(this).addClass('active'); return false; });
    $('li#button3 a').click(function() { carousel.scroll(4); $('ul#widgetnavbar li a').removeClass('active'); $(this).addClass('active'); return false; });
    $('li#button4 a').click(function() { carousel.scroll(5); $('ul#widgetnavbar li a').removeClass('active'); $(this).addClass('active'); return false; });
};


function openSwitchRegion(page)
{	
	opencenteredpopup(page,'AKSwitch',302,602,'no','yes');	
}
function openRecipePrint(page)
{	
	opencenteredpopup(page,'AKRecipePrint',600,800,'yes','yes');	
}
function openSiteCredits(page)
{	
	opencenteredpopup(page,'AKSiteCredits',302,602,'yes','yes');	
}


function opencenteredpopup(page,pagename,h,w,rs,sbs) 
{ 
  l = (screen.width/2)-(w/2);
  t = (screen.height/2)-(h/2);

  w = window.open(page, pagename,"height="+h+",width="+w+",top="+t+",left="+l+",resizable="+rs+",scrollbars="+sbs);
  w.focus();

}



function CheckTandCs(sender, args)
{
return;
    var cbxTandCs = findControl1('1cbxTandCs');

    if(!cbxTandCs.checked)
    {  
    
         args.IsValid = false;
         return;
    }
    args.IsValid = true;
}

function findControl1(ControlName)
{ var ret=null;
var aControls = document.getElementsByTagName("input");
if (aControls)
{ for (var i=0; i< aControls.length ; i++)
{
if (aControls[i].id.lastIndexOf(ControlName) == aControls[i].id.length -
ControlName.length &&
aControls[i].id.length != ControlName.length &&
aControls[i].id.lastIndexOf(ControlName) > 0 )
{
ret =aControls[i];
break;
}
}
}
return ret;
}


// THIS IS THE DREAMWEAVER IMAGE SWAP CODE


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function openWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}


// The Offset Method
// Originally By Brandon Aaron, part of the Dimension Plugin
// http://jquery.com/plugins/project/dimensions

jQuery.fn.offset = function() {
	var left = 0, top = 0, elem = this[0], results;
	
	if ( elem ) with ( jQuery.browser ) {
		var	absolute     = jQuery.css(elem, "position") == "absolute", 
		    parent       = elem.parentNode, 
		    offsetParent = elem.offsetParent, 
		    doc          = elem.ownerDocument,
		    safari2      = safari && parseInt(version) < 522;
	
		// Use getBoundingClientRect if available
		if ( elem.getBoundingClientRect ) {
			box = elem.getBoundingClientRect();
		
			// Add the document scroll offsets
			add(
				box.left + Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft),
				box.top  + Math.max(doc.documentElement.scrollTop,  doc.body.scrollTop)
			);
		
			// IE adds the HTML element's border, by default it is medium which is 2px
			// IE 6 and IE 7 quirks mode the border width is overwritable by the following css html { border: 0; }
			// IE 7 standards mode, the border is always 2px
			if ( msie ) {
				var border = jQuery("html").css("borderWidth");
				border = (border == "medium" || jQuery.boxModel && parseInt(version) >= 7) && 2 || border;
				add( -border, -border );
			}
	
		// Otherwise loop through the offsetParents and parentNodes
		} else {
		
			// Initial element offsets
			add( elem.offsetLeft, elem.offsetTop );
		
			// Get parent offsets
			while ( offsetParent ) {
				// Add offsetParent offsets
				add( offsetParent.offsetLeft, offsetParent.offsetTop );
			
				// Mozilla and Safari > 2 does not include the border on offset parents
				// However Mozilla adds the border for table cells
				if ( mozilla && /^t[d|h]$/i.test(parent.tagName) || !safari2 )
					border( offsetParent );
				
				// Safari <= 2 doubles body offsets with an absolutely positioned element or parent
				if ( safari2 && !absolute && jQuery.css(offsetParent, "position") == "absolute" )
					absolute = true;
			
				// Get next offsetParent
				offsetParent = offsetParent.offsetParent;
			}
		
			// Get parent scroll offsets
			while ( parent.tagName && !/^body|html$/i.test(parent.tagName) ) {
				// Work around opera inline/table scrollLeft/Top bug
				if ( !/^inline|table-row.*$/i.test(jQuery.css(parent, "display")) )
					// Subtract parent scroll offsets
					add( -parent.scrollLeft, -parent.scrollTop );
			
				// Mozilla does not add the border for a parent that has overflow != visible
				if ( mozilla && jQuery.css(parent, "overflow") != "visible" )
					border( parent );
			
				// Get next parent
				parent = parent.parentNode;
			}
		
			// Safari doubles body offsets with an absolutely positioned element or parent
			if ( safari2 && absolute )
				add( -doc.body.offsetLeft, -doc.body.offsetTop );
		}

		// Return an object with top and left properties
		results = { top: top, left: left };
	}

	return results;

	function border(elem) {
		add( jQuery.css(elem, "borderLeftWidth"), jQuery.css(elem, "borderTopWidth") );
	}

	function add(l, t) {
		left += parseInt(l) || 0;
		top += parseInt(t) || 0;
	}
};
