/* setting up the session variables for contact us page*/
function processCallToAction(title, url){

	//MM: TODO: change the below to page title instead of productName
	//window.frames['setupSession'].document.getElementById("pageTitle").value = title;

	window.frames['setupSession'].document.getElementById("productName").value = title;
	window.frames['setupSession'].document.getElementById("submissionForm").submit(); 
	setTimeout(function() { document.location = url; }, 600); 
}

/**
* DD_belatedPNG: Adds IE6 support: PNG images for CSS background-image and HTML <IMG/>.
* Author: Drew Diller
* Email: drew.diller@gmail.com
* URL: http://www.dillerdesign.com/experiment/DD_belatedPNG/
* Version: 0.0.8a
* Licensed under the MIT License: http://dillerdesign.com/experiment/DD_belatedPNG/#license
*
* Example usage:
* DD_belatedPNG.fix('.png_bg'); // argument is a CSS selector
* DD_belatedPNG.fixPng( someNode ); // argument is an HTMLDomElement
**/
if ($.browser.msie && $.browser.version < 7) {
var DD_belatedPNG={ns:"DD_belatedPNG",imgSize:{},delay:10,nodesFixed:0,createVmlNameSpace:function(){if(document.namespaces&&!document.namespaces[this.ns]){document.namespaces.add(this.ns,"urn:schemas-microsoft-com:vml")}},createVmlStyleSheet:function(){var b,a;b=document.createElement("style");b.setAttribute("media","screen");document.documentElement.firstChild.insertBefore(b,document.documentElement.firstChild.firstChild);if(b.styleSheet){b=b.styleSheet;b.addRule(this.ns+"\\:*","{behavior:url(#default#VML)}");b.addRule(this.ns+"\\:shape","position:absolute;");b.addRule("img."+this.ns+"_sizeFinder","behavior:none; border:none; position:absolute; z-index:-1; top:-10000px; visibility:hidden;");this.screenStyleSheet=b;a=document.createElement("style");a.setAttribute("media","print");document.documentElement.firstChild.insertBefore(a,document.documentElement.firstChild.firstChild);a=a.styleSheet;a.addRule(this.ns+"\\:*","{display: none !important;}");a.addRule("img."+this.ns+"_sizeFinder","{display: none !important;}")}},readPropertyChange:function(){var b,c,a;b=event.srcElement;if(!b.vmlInitiated){return}if(event.propertyName.search("background")!=-1||event.propertyName.search("border")!=-1){DD_belatedPNG.applyVML(b)}if(event.propertyName=="style.display"){c=(b.currentStyle.display=="none")?"none":"block";for(a in b.vml){if(b.vml.hasOwnProperty(a)){b.vml[a].shape.style.display=c}}}if(event.propertyName.search("filter")!=-1){DD_belatedPNG.vmlOpacity(b)}},vmlOpacity:function(b){if(b.currentStyle.filter.search("lpha")!=-1){var a=b.currentStyle.filter;a=parseInt(a.substring(a.lastIndexOf("=")+1,a.lastIndexOf(")")),10)/100;b.vml.color.shape.style.filter=b.currentStyle.filter;b.vml.image.fill.opacity=a}},handlePseudoHover:function(a){setTimeout(function(){DD_belatedPNG.applyVML(a)},1)},fix:function(a){if(this.screenStyleSheet){var c,b;c=a.split(",");for(b=0;b<c.length;b++){this.screenStyleSheet.addRule(c[b],"behavior:expression(DD_belatedPNG.fixPng(this))")}}},applyVML:function(a){a.runtimeStyle.cssText="";this.vmlFill(a);this.vmlOffsets(a);this.vmlOpacity(a);if(a.isImg){this.copyImageBorders(a)}},attachHandlers:function(i){var d,c,g,e,b,f;d=this;c={resize:"vmlOffsets",move:"vmlOffsets"};if(i.nodeName=="A"){e={mouseleave:"handlePseudoHover",mouseenter:"handlePseudoHover",focus:"handlePseudoHover",blur:"handlePseudoHover"};for(b in e){if(e.hasOwnProperty(b)){c[b]=e[b]}}}for(f in c){if(c.hasOwnProperty(f)){g=function(){d[c[f]](i)};i.attachEvent("on"+f,g)}}i.attachEvent("onpropertychange",this.readPropertyChange)},giveLayout:function(a){a.style.zoom=1;if(a.currentStyle.position=="static"){a.style.position="relative"}},copyImageBorders:function(b){var c,a;c={borderStyle:true,borderWidth:true,borderColor:true};for(a in c){if(c.hasOwnProperty(a)){b.vml.color.shape.style[a]=b.currentStyle[a]}}},vmlFill:function(e){if(!e.currentStyle){return}else{var d,f,g,b,a,c;d=e.currentStyle}for(b in e.vml){if(e.vml.hasOwnProperty(b)){e.vml[b].shape.style.zIndex=d.zIndex}}e.runtimeStyle.backgroundColor="";e.runtimeStyle.backgroundImage="";f=true;if(d.backgroundImage!="none"||e.isImg){if(!e.isImg){e.vmlBg=d.backgroundImage;e.vmlBg=e.vmlBg.substr(5,e.vmlBg.lastIndexOf('")')-5)}else{e.vmlBg=e.src}g=this;if(!g.imgSize[e.vmlBg]){a=document.createElement("img");g.imgSize[e.vmlBg]=a;a.className=g.ns+"_sizeFinder";a.runtimeStyle.cssText="behavior:none; position:absolute; left:-10000px; top:-10000px; border:none; margin:0; padding:0;";c=function(){this.width=this.offsetWidth;this.height=this.offsetHeight;g.vmlOffsets(e)};a.attachEvent("onload",c);a.src=e.vmlBg;a.removeAttribute("width");a.removeAttribute("height");document.body.insertBefore(a,document.body.firstChild)}e.vml.image.fill.src=e.vmlBg;f=false}e.vml.image.fill.on=!f;e.vml.image.fill.color="none";e.vml.color.shape.style.backgroundColor=d.backgroundColor;e.runtimeStyle.backgroundImage="none";e.runtimeStyle.backgroundColor="transparent"},vmlOffsets:function(d){var h,n,a,e,g,m,f,l,j,i,k;h=d.currentStyle;n={W:d.clientWidth+1,H:d.clientHeight+1,w:this.imgSize[d.vmlBg].width,h:this.imgSize[d.vmlBg].height,L:d.offsetLeft,T:d.offsetTop,bLW:d.clientLeft,bTW:d.clientTop};a=(n.L+n.bLW==1)?1:0;e=function(b,p,q,c,s,u){b.coordsize=c+","+s;b.coordorigin=u+","+u;b.path="m0,0l"+c+",0l"+c+","+s+"l0,"+s+" xe";b.style.width=c+"px";b.style.height=s+"px";b.style.left=p+"px";b.style.top=q+"px"};e(d.vml.color.shape,(n.L+(d.isImg?0:n.bLW)),(n.T+(d.isImg?0:n.bTW)),(n.W-1),(n.H-1),0);e(d.vml.image.shape,(n.L+n.bLW),(n.T+n.bTW),(n.W),(n.H),1);g={X:0,Y:0};if(d.isImg){g.X=parseInt(h.paddingLeft,10)+1;g.Y=parseInt(h.paddingTop,10)+1}else{for(j in g){if(g.hasOwnProperty(j)){this.figurePercentage(g,n,j,h["backgroundPosition"+j])}}}d.vml.image.fill.position=(g.X/n.W)+","+(g.Y/n.H);m=h.backgroundRepeat;f={T:1,R:n.W+a,B:n.H,L:1+a};l={X:{b1:"L",b2:"R",d:"W"},Y:{b1:"T",b2:"B",d:"H"}};if(m!="repeat"||d.isImg){i={T:(g.Y),R:(g.X+n.w),B:(g.Y+n.h),L:(g.X)};if(m.search("repeat-")!=-1){k=m.split("repeat-")[1].toUpperCase();i[l[k].b1]=1;i[l[k].b2]=n[l[k].d]}if(i.B>n.H){i.B=n.H}d.vml.image.shape.style.clip="rect("+i.T+"px "+(i.R+a)+"px "+i.B+"px "+(i.L+a)+"px)"}else{d.vml.image.shape.style.clip="rect("+f.T+"px "+f.R+"px "+f.B+"px "+f.L+"px)"}},figurePercentage:function(d,c,f,a){var b,e;e=true;b=(f=="X");switch(a){case"left":case"top":d[f]=0;break;case"center":d[f]=0.5;break;case"right":case"bottom":d[f]=1;break;default:if(a.search("%")!=-1){d[f]=parseInt(a,10)/100}else{e=false}}d[f]=Math.ceil(e?((c[b?"W":"H"]*d[f])-(c[b?"w":"h"]*d[f])):parseInt(a,10));if(d[f]%2===0){d[f]++}return d[f]},fixPng:function(c){c.style.behavior="none";var g,b,f,a,d;if(c.nodeName=="BODY"||c.nodeName=="TD"||c.nodeName=="TR"){return}c.isImg=false;if(c.nodeName=="IMG"){if(c.src.toLowerCase().search(/\.png$/)!=-1){c.isImg=true;c.style.visibility="hidden"}else{return}}else{if(c.currentStyle.backgroundImage.toLowerCase().search(".png")==-1){return}}g=DD_belatedPNG;c.vml={color:{},image:{}};b={shape:{},fill:{}};for(a in c.vml){if(c.vml.hasOwnProperty(a)){for(d in b){if(b.hasOwnProperty(d)){f=g.ns+":"+d;c.vml[a][d]=document.createElement(f)}}c.vml[a].shape.stroked=false;c.vml[a].shape.appendChild(c.vml[a].fill);c.parentNode.insertBefore(c.vml[a].shape,c)}}c.vml.image.shape.fillcolor="none";c.vml.image.fill.type="tile";c.vml.color.fill.on=false;g.attachHandlers(c);g.giveLayout(c);g.giveLayout(c.offsetParent);c.vmlInitiated=true;g.applyVML(c)}};try{document.execCommand("BackgroundImageCache",false,true)}catch(r){}DD_belatedPNG.createVmlNameSpace();DD_belatedPNG.createVmlStyleSheet();
}


/*pageTitle end*/

/* fixing ie glitch in jquery's fadeIn/fadeOut */
(function($) {
    $.fn.newFadeIn = function(speed, callback) {
        $(this).fadeIn(speed, function() {
            if(jQuery.browser.msie)
                $(this).get(0).style.removeAttribute('filter');
            if(callback != undefined)
                callback();
        });
    };
    $.fn.newFadeOut = function(speed, callback) {
        $(this).fadeOut(speed, function() {
            if(jQuery.browser.msie)
                $(this).get(0).style.removeAttribute('filter');
            if(callback != undefined)
                callback();
        });
    };
})(jQuery);



/* fix console.log messages in IE */
if(window['console'] === undefined)
   window.console = { log: function(){} 
}; 


/* replaceClass */
jQuery.fn.extend({
        'replaceClass': function(remC,addC){
            return this.each(function() {
$(this).removeClass(remC).addClass(addC);
});
        }
}); 

/* BigTarget */
(function($){$.fn.bigTarget=function(options){debug(this);var opts=$.extend({},$.fn.bigTarget.defaults,options);return this.each(function(){var $a=$(this);var href=$a.attr('href');var title=$a.attr('title');var o=$.meta?$.extend({},opts,$a.data()):opts;$a.parents(o.clickZone).hover(function(){var $h=$(this);$h.addClass(o.hoverClass);if(typeof o.title!='undefined'&&o.title===true&&title!=''){$h.attr('title',title);}},function(){var $h=$(this);$h.removeClass(o.hoverClass);if(typeof o.title!='undefined'&&o.title===true&&title!=''){$h.removeAttr('title');}}).click(function(){if(getSelectedText()=="")
{if($a.is('[rel*=external]')){window.open(href);return false;}
else{window.location=href;}}});});};function debug($obj){if(window.console&&window.console.log)
window.console.log('bigTarget selection count: '+$obj.size());};function getSelectedText(){if(window.getSelection){return window.getSelection().toString();}
else if(document.getSelection){return document.getSelection();}
else if(document.selection){return document.selection.createRange().text;}};$.fn.bigTarget.defaults={hoverClass:'hover',clickZone:'li:eq(0)',title:true};})(jQuery);

/* jcarousel lite 1.0.1 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(6($){$.1g.1w=6(o){o=$.1f({r:n,x:n,N:n,17:q,J:n,L:1a,16:n,y:q,u:12,H:3,B:0,k:1,K:n,I:n},o||{});8 G.R(6(){p b=q,A=o.y?"15":"w",P=o.y?"t":"s";p c=$(G),9=$("9",c),E=$("10",9),W=E.Y(),v=o.H;7(o.u){9.1h(E.D(W-v-1+1).V()).1d(E.D(0,v).V());o.B+=v}p f=$("10",9),l=f.Y(),4=o.B;c.5("1c","H");f.5({U:"T",1b:o.y?"S":"w"});9.5({19:"0",18:"0",Q:"13","1v-1s-1r":"S","z-14":"1"});c.5({U:"T",Q:"13","z-14":"2",w:"1q"});p g=o.y?t(f):s(f);p h=g*l;p j=g*v;f.5({s:f.s(),t:f.t()});9.5(P,h+"C").5(A,-(4*g));c.5(P,j+"C");7(o.r)$(o.r).O(6(){8 m(4-o.k)});7(o.x)$(o.x).O(6(){8 m(4+o.k)});7(o.N)$.R(o.N,6(i,a){$(a).O(6(){8 m(o.u?o.H+i:i)})});7(o.17&&c.11)c.11(6(e,d){8 d>0?m(4-o.k):m(4+o.k)});7(o.J)1p(6(){m(4+o.k)},o.J+o.L);6 M(){8 f.D(4).D(0,v)};6 m(a){7(!b){7(o.K)o.K.Z(G,M());7(o.u){7(a<=o.B-v-1){9.5(A,-((l-(v*2))*g)+"C");4=a==o.B-v-1?l-(v*2)-1:l-(v*2)-o.k}F 7(a>=l-v+1){9.5(A,-((v)*g)+"C");4=a==l-v+1?v+1:v+o.k}F 4=a}F{7(a<0||a>l-v)8;F 4=a}b=12;9.1o(A=="w"?{w:-(4*g)}:{15:-(4*g)},o.L,o.16,6(){7(o.I)o.I.Z(G,M());b=q});7(!o.u){$(o.r+","+o.x).1n("X");$((4-o.k<0&&o.r)||(4+o.k>l-v&&o.x)||[]).1m("X")}}8 q}})};6 5(a,b){8 1l($.5(a[0],b))||0};6 s(a){8 a[0].1k+5(a,\'1j\')+5(a,\'1i\')};6 t(a){8 a[0].1t+5(a,\'1u\')+5(a,\'1e\')}})(1x);',62,96,'||||curr|css|function|if|return|ul|||||||||||scroll|itemLength|go|null||var|false|btnPrev|width|height|circular||left|btnNext|vertical||animCss|start|px|slice|tLi|else|this|visible|afterEnd|auto|beforeStart|speed|vis|btnGo|click|sizeCss|position|each|none|hidden|overflow|clone|tl|disabled|size|call|li|mousewheel|true|relative|index|top|easing|mouseWheel|padding|margin|200|float|visibility|append|marginBottom|extend|fn|prepend|marginRight|marginLeft|offsetWidth|parseInt|addClass|removeClass|animate|setInterval|0px|type|style|offsetHeight|marginTop|list|jCarouselLite|jQuery'.split('|'),0,{}))


/* from flash de-con */

var VERSION = "2.10";
var DEFAULT_ISO  = "en-gb";
var DEFAULT_MODE = "full";
var MIN_FLASH = "9.0.115";

var URLParams = getURLParams();

function getURLParams()
{
var o = {};
if( !document.location.search.length ) return o;

var params = document.location.search.substr( 1 ).split( "&" );
var parts;
for( var i in params ){
parts = params[i].split( "=" );
o[ parts[0] ] = parts[1];
}
return o;
}

function getParam( name,defaultvalue )
{
return URLParams[ name ] || defaultvalue;
}

function createFlash( flashPath,containerID,width,height )
{
flashPath += flashPath.indexOf( "?" ) == -1 ? "?v=" : "&v=";
flashPath += VERSION;

var vars = {
iso:  getParam( "iso",DEFAULT_ISO ).replace( "_","-" ).toLowerCase(),
mode: getParam( "mode",DEFAULT_MODE ).toLowerCase(),
trackid: getParam( "trackid",undefined ),
clear: getParam( "clear",undefined ),
version:  VERSION,
url: escape( document.location.toString() )
};

// Look for pre-defined flashvars //
if( window.flashvars ){
for( var i in window.flashvars ) vars[i] = window.flashvars[i];
}

window.flashvars = vars;


var params = {
bgcolor:  "#FFFFFF",
allowfullscreen:  "true",
allowscriptaccess:  "always",
menu:  "false",
wmode: "window"
};


// Look for pre-defined flashparams //
if( window.flashparams )
{
for( var i in window.flashparams ) 
{
params[i] = window.flashparams[i];
}
}
window.flashparams = params;

var attributes = { 
//id: "content"
};

//alert( flashvars.mode );

swfobject.embedSWF( 
flashPath,
containerID,
width,height,
MIN_FLASH,
"./swf/expressinstall.swf",
flashvars,params,attributes 
);
}

function track(type,name,path)
{
// Types: view,element,event //

switch( new String( type ).toLowerCase() ){
case "view":
window.parent.cmCreatePageviewTag( name,path );
return;

case "element":
window.parent.cmCreatePageElementTag( name,path );
return;

case "event":
window.parent.cmCreateConversionEventTag( name,"2",path,"50" );
return;
}

//alert( "tracking: " + path );
}

// Stubs //
function dummy( a,b,c,d ){ console.info( a + "," + b + "," + c + "," + d ); }
if( !window.parent.cmCreatePageviewTag ) window.parent.cmCreatePageviewTag = dummy;
if( !window.parent.cmCreatePageElementTag ) window.parent.cmCreatePageElementTag = dummy;
if( !window.parent.cmCreateConversionEventTag ) window.parent.cmCreateConversionEventTag = dummy;


// tracking for the homepage slideshow
function doTracking(value) {
pageTracker._trackEvent ('HomepageSlideShow',value);
}

/* main */
var alico = function() {
var pub = {};
/*
var strPub = "test";
function func1() {};
pub.function1 = function(){
   };
   */

pub.init = function() {
/*lets fix that side collumn the lazy js coder way :D*/

if($("#mainContainer").height() < $("#leftPanel").height()) {
var left = $("#leftPanel").height();
$("#mainContainer").height(left + 100);
}

$("#sideNavBox li a").bigTarget();
$(".withImage a.buttonRead").bigTarget({
clickZone : 'div:eq(2)' // jQuery parent selector
});

/* for FAQ - expand the first accordion if there's only one */
if ($("div.accordion.ui-accordion.faq div.acContent").length==1) {
$(".accordion:first h3").click()
}

// fuzzy text in ie6
if ($(".ie6 .fancyProductPanel .tabs .tab")) {
$(".ie6 .fancyProductPanel .tabs .tab").click(function(){
$(".ie6 .productDetails").each(function(e) {
if (($(this).css("filter")!="alpha(opacity=0)") && $(this).css("filter")!="none" || $(this).css("filter")!="auto") {
$(this).css("filter","auto");
}
});
});
}

//fixes ie6 products page issue jumping to bottom
if ($(".promoBox .hContent, .fancyProductPanel").length>0){setTimeout(function(){window.scrollTo(0, 0);$(".dividerContainer .promoBox").hide().show().mouseover()},500)}

/*
inject url params into contact us links in bottomSlideDown
*/
var loadContactLink = function(){
  // set cookie when the page has referral
  var referrer = document.referrer;
  var bMatch = false;
  var ignoredUrls=
   ["http://uae.alico.com",
   "https://uae.alico.com",
   "http://www.uae.alico.com",
   "https://www.aue.alico.com",
   "http://stage.uae.alico.com",
   "https://stage.uae.alico.com",
   "http://secure.uae.alico.com",
   "https://secure.uae.alico.com"];
  var ignoredUrlPattern=/^http(s)?:\/\/(((stage|stage2|stage|teststage|www)\.)?([a-z]{0,3}\.)?alico.com|(www\.)?interamericana.cl)/;

  /*
 for (var i=0; i<ignoredUrls.length; i++) {
   if (referrer.indexOf(ignoredUrls[i])==0) bMatch = true;   
}
*/
if (referrer.match(ignoredUrlPattern)) bMatch = true;   
 
 // if the referrer is not from our domain, then this is the first time. 
 if (!bMatch) {
 /*
   var date = new Date();
   date.setTime(date.getTime()+(1*24*60*60*1000));
 */
   document.cookie = 'alicoReferral=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
   document.cookie = "alicoReferral="+document.referrer+"; expires='"/*+ date.toGMTString()*/ +"'; path=/"
   window.name = "alicoReferral="+document.referrer;
   
   //MM: TODO: set the referrer on the IFRAME & submit the setupSession
   //window.frames['setupSession'].document.getElementById("referrerUrl").value = getCookie("alicoReferral");
   //window.frames['setupSession'].document.getElementById("submissionForm").submit(); 
}

if (referrer=="") {
	document.cookie = 'alicoReferral=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
	window.name="alicoReferral=;"
}

/*
// contact me buttons
if ($("#bottomSlideDownContent .button[title='Contact me']").length>0) {
   var productType = $("#productType").html();
   if (productType=="" || productType==null) productType="individual";
   var contactLink = $(".bottomSlideDown #bottomSlideDownContent .button[title='Contact me']").attr("href")+"?productType="+productType+"&customerType=new";
   $(".bottomSlideDown #bottomSlideDownContent .button[title='Contact me']").attr("href",contactLink);
}

// contact us on global nav
if ($("#navContainer #navList li a[href*=contact-us.html]").length>0) {
   var eleContactNav = $("#navContainer #navList li a[href*=contact-us.html]");
   var contactLink = eleContactNav.attr("href")+"?productType=individual&customerType=existing";
   eleContactNav.attr("href",contactLink);
}

// submit your contact details link
if ($("#mainPanel .greyParagraph p a:has('strong'):contains('submit your contact details')").length >0 && window.location.toString().indexOf("employee-benefits")>0) {
var eleContactLink = $("#mainPanel .greyParagraph p a:has('strong'):contains('submit your contact details')");
var contactLink = eleContactLink.attr("href")+"?productType=group&customerType=new";
eleContactLink.attr("href",contactLink);    
}

// sitemap link
if (window.location.toString().indexOf("sitemap")>0 && $(".siteMapColumn li ul li a:contains('Contact Us')").length >0) {
var eleContactLink = $(".siteMapColumn li ul li a:contains('Contact Us')");
var contactLink = eleContactLink.attr("href")+"?productType=individual&customerType=existing";
eleContactLink.attr("href",contactLink);    
}

//MM: TODO: remove this stuff below, the referrer url should get sent to the backend via the contact us page.
// refer to the output.asp of Form Page template and uncomment the TODO that sends the referrerUrl to the backend.

*/
// modify contactFrame src on contact us page
if ($("#icontact").length>0) { // iframe's id

	if (window.location.href.split("?")[1] != null) {
		$("#icontact").attr("src", $("#icontact").attr("src") + "?" + window.location.href.split("?")[1] + "&referrerURL=" + escape(getCookie("alicoReferral")) + "&prevPage=" + document.referrer);
	} else {
		$("#icontact").attr("src", $("#icontact").attr("src") + "" + "&referrerURL=" + escape(getCookie("alicoReferral")) + "&prevPage=" + document.referrer);
	}
} else if ($("#groupFrame").length>0) { // iframe's id
	if (window.location.href.split("?")[1] != null) {
		$("#groupFrame").attr("src", $("#groupFrame").attr("src") + "?" + window.location.href.split("?")[1] + "&referrerURL=" + escape(getCookie("alicoReferral")) + "&prevPage=" + document.referrer);
	} else {
		$("#groupFrame").attr("src", $("#groupFrame").attr("src") + "" + "&referrerURL=" + escape(getCookie("alicoReferral")) + "&prevPage=" + document.referrer);
	}
}

}();// end of loadContactLink

if ($.browser.msie && $.browser.version == 6) {
// fix ie 6 bugs on accordions
$('.accordion').bind('accordionchange', function(event, ui){
setTimeout(function(){
$(".moduleRow .promoBox").hide().show();
}, 200);
});

//Mihir: commenting out this below line as this line throws an error and causes all javascript to fail.
//@Nick - please enable this line, publish this file to Staging UK target        
DD_belatedPNG.fix('.subbrandlogo img');
}
};
return pub;
}();
alico.init();


window.alicoPage = {}
window.alicoPage.StoryGallery = {
init: function(){
        if ($(".fancyProductPanel").length > 0) {
            $('<div id="loader"></div>').insertBefore('div#prev');
            $('.mainPanel').each(function(i, el) {
                var n = i + 1;
                $('#prev').addClass('prev' + n);
                $('#next').addClass('next' + n);
            });

            $('.mainPanel').each(function(i, el) {
                var n = i + 1;
                if ($(el).find('.mainPanelSlide').size() > 1) {
                    $(el).jCarouselLite({
                        btnNext: ".next" + n,
                        btnPrev: ".prev" + n,
                        btnGo: $('#subPanel' + n + " .featuredStory"),
                        speed: 500,
                        circular: true,
                        visible: 1,
                        start: 0,
                        beforeStart: function(a) {
                            $('#subPanelSlide' + n + ' .featuredStory:eq(' + (parseInt(a[0].id.substring(a[0].id.length - 1, a[0].id.length)) - 1).toString() + ')').removeClass("active");
                            $(".fancyProductPanel .mainPanelContainer .mainPanelSlide .content").css("overflow", "hidden");
                        },
                        afterEnd: function(a) {
                            $('#subPanelSlide' + n + ' .featuredStory:eq(' + (parseInt(a[0].id.substring(a[0].id.length - 1, a[0].id.length)) - 1).toString() + ')').addClass("active");
                            setTimeout("$('.fancyProductPanel .mainPanelContainer .mainPanelSlide .content').css('overflow', 'auto');", 0);
                        }
                    })
                }
                else {
                    $(this).css({marginLeft:'-50px'});
                    $(el).find('.mainPanelSlides').css({'visibility':'visible'})
                }
            })
            $(".fancyProductPanel .tabs .tab").each(function(i, el) {
                var n = i + 1;
                $(this).attr('href','#'+n );
            
            
                $(el).click(function() {
                    var $mainPan = $("#mainPanel" + n)
                    if($mainPan.find('.mainPanelSlide').size() > 1){
                        hideShowHelper( $mainPan, $("#subPanelSlide" + n));
                        $('.introPanel:eq(' + i + ')').siblings().hide().end().show();
                        
                        $("#prev").attr('class', "prev" + n);
                        $("#next").attr('class', "next" + n);
                        
                    }
                    else{
                      hideShowHelper( $mainPan, $("#subPanelSlide" + n));
                      $mainPan.find('.mainPanelSlide').show();  
                    }
                    $(this).addClass("active");
                   // return false;
                })

            });


            function initializeSet() {
                $('.introPanel:eq(0)').show().siblings().hide()
                $('.mainPanel').each(function(i, el) {
                    var n = i + 1;
                    if (i > 0) {

                        $(el).hide();
                        $(el).fadeTo(1, 1);
                        $('#subPanelSlide' + n).hide();
                    }
                    $('#subPanelSlide' + n + ' .featuredStory:eq(0)').addClass('active');
                })
                //$("#prev").attr("class","prev1");
                //$("#next").attr("class","next1");
                $('#loader').hide();
            }

            function hideShowHelper(ele1, ele2) {
                $('.subPanelSlide .featuredStory:eq(0)').click();
                $(".mainPanel").newFadeOut(0);
                $(".subPanelSlide").newFadeOut(0);
                $(".fancyProductPanel .tabs a.tab").removeClass("active");
                ele1.show(300,function(){ele1.css("filter","auto")});
                ele2.show(300,function(){ele2.css("filter","auto")});
            }


            initializeSet();



         $(window).bind( 'hashchange', function(e) {
            var url = $.param.fragment() -1;
            if ($('a.tab').eq(url).hasClass('active')){
              return false;
            }else{
             $('a.tab').eq(url).trigger('click');   
            }
          });
        
          $(window).trigger( 'hashchange' );
        }
    
    }
}
window.alicoPage.ProductFinder = {
    init : function(){
        
        if ($(".fancyProductPanel").length > 0) {
                $('<div id="loader"></div>').insertBefore('div#prev');
                $('.subPanelSlide').each(function(i,el){
                var n = i+1;
                $('#prev').addClass('prev' + n);
                $('#next').addClass('next' + n);
            });

        $('<input type="button" style="display:none;" value="to Zero" class="toZero"/>').appendTo($('.subPanel'))
        
        $('.subPanelSlide').each(function(i,el){ 
            var n = i+1;
            if($(el).find('.productDescription').size() > 4){
                $(el).find('.productDescriptions').jCarouselLite({
                    btnNext: ".next" + n, 
                    btnPrev: ".prev" + n, 
                    speed: 500, 
                    circular: false, 
                    visible: 4,
                    start: 0,
                    scroll:1,
                    btnGo: ['input.toZero'],
                    beforeStart:function(a){
                    
                    },
                    afterEnd: function(a){
                        $('.current').removeClass('current');
                        $(a[0]).addClass('current');
                        console.log(a[0] + " ");
                        $('#subPanelSlide' + n + ' .productDescription:eq('+ (parseInt(a[0].id.substring(a[0].id.length -1, a[0].id.length)) - 1).toString() +')').addClass("active");                    
                    } 
                })
            }        
        })
        $(".fancyProductPanel .tabs .tab").each(function(i, el){
            var n = i + 1;
            $(this).attr('href','#'+n );
              
            $(el).click(function(){
            hideShowHelper($("#mainPanel" + n),$("#subPanelSlide" + n));
            $(this).addClass("active");        
            $("#prev").attr('class',"prev"+n);
            $("#next").attr('class',"next"+n);

            if($('#subPanelSlide'+n).find('.productDescription').size() > 4){
                $('input.toZero').click();
            }
            else{
                $("#prev, #next").addClass('disabled');
            }
      //  return false;
        })

        }) 


        function initializeSet(){
            $('.mainPanel').each(function(i,el){
                var n = i+1;
                if(i > 0){
                    $(el).hide();
                    $('#subPanelSlide'+n).hide();
                }
                $('#subPanelSlide'+n+' .featuredStory:eq(0)').addClass('active');
            }) 
            
            $("#prev").attr("class","prev1 disabled");
            $("#next").attr("class","next1");
            $('#loader').hide();

            $('input.toZero').click();
            $('.fancyProductPanel .tabs .tab:eq(0)').click();
        } 

        function hideShowHelper(ele1,ele2) {        
            $(".mainPanel").hide(200);
            $(".subPanelSlide").hide(200);
            $(".fancyProductPanel .tabs a.tab").removeClass("active");
            ele1.show(500,function(){ele1.css("filter","auto")});
            ele2.show(500,function(){ele2.css("filter","auto")});
if (console.log) console.log(ele1.css("filter"));
        }
        initializeSet();

         $(window).bind( 'hashchange', function(e) {
            var url = $.param.fragment() -1;
            if ($('a.tab').eq(url).hasClass('active')){
              return false;
            }else{
             $('a.tab').eq(url).trigger('click');   
            }
          });
        
          $(window).trigger( 'hashchange' );
        }        
    }
}





/*
 *
 * Text sizer
$("*").each(function(el){
    var size = parseInt($(this).css("font-size").replace(/px/, ""));
    var newSize = size + 2 + "px";
    $(this).css("font-size",newSize);
})
 * 
 * 
 */
 
 // public function
 
function getCookie(c_name)
{
  if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
  }
  
  if (window.name!="")
  {
  c_start=window.name.indexOf(c_name + "=");
  if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=window.name.length;
return unescape(window.name.substring(c_start,c_end));
}
  }
return "";
}