// try {
//     console.assert(1);
// } catch(e) {
//     if (typeof loadFirebugConsole == 'function') {
//          loadFirebugConsole();
//     }  else {
//         console = {
//             log: function() {},
//             debug: function() {},
//             info: function() {},
//             warn: function() {},
//             assert: function() {}
//         }
//     }
// }

// this is not needed. console should only be used in dev.

//------------------------------------------
// Set Psuedo Class fix for <IE6 on Top Nav
//------------------------------------------


document.write('<link rel="stylesheet" type="text/css" href="/static/css/js.css" media="all"/>');


/* slideshow scripting */
var CreateCrossFade = new Class({
	Implements:[Options,Events],
	options:{
		stage: false,	// the slide stage/containing div
		slides: [], 	// the individual slide element
		autotime: 4000,
		links: false
	},

	initialize:function(options){
		this.setOptions(options);
		this.stage = $(this.options.stage); if(!(this.stage)) return;
		this.addItems(this.options.slides);

        this.slides.each(function(slide, i) {
			slide.setProperty('id', 'slide00'+i)
			if(i == 0) return;
            slide.setStyle('opacity', 0);
        }, this);
		
		this.autotime = this.options.autotime;
		this.links = this.options.links;
		this.links[0].addClass('on');
		
        this.position = 0;
		this.auto();
	},

	slides:[],
	
	addItems:function(items){
		$$(items).each(function(item){this.slides.include($(item));}, this);
	},
	
	addItem:function(item){
		this.addItems($splat($(item)));
	},
	
	_transition: function(stack,from, to) {
        var fromer = stack[from],tooer = stack[to];
		
		fromer.get('tween', {property:'opacity', duration: 800, 
			onStart: function(){
				var h2sIFR = fromer.getChildren('div.flag')[0].getFirst().getFirst();
				if(h2sIFR.hasClass('sIFR-replaced')) h2sIFR.setStyle('visibility', 'hidden');
			}}).start(0);

		tooer.get('tween', {property:'opacity', duration: 600, 
			onStart: function(){
				var h2sIFR = tooer.getChildren('div.flag')[0].getFirst().getFirst();
				if(h2sIFR.hasClass('sIFR-replaced')) h2sIFR.setStyle('visibility', 'hidden');
			},
			onComplete:function(){
				var h2sIFR = tooer.getChildren('div.flag')[0].getFirst().getFirst();
				if(h2sIFR.hasClass('sIFR-replaced')) h2sIFR.setStyle('visibility', 'visible');
			}}).start(1);
    },
	
	next: function() {
		var next = this.position + 1 > this.slides.length - 1 ? 0 : this.position + 1;
		this._transition(this.slides, this.position, this.position = next);
	},
	back: function() {
		var back = this.position - 1 < 0 ? this.slides.length - 1 : this.position - 1;
		this._transition(this.slides, this.position, this.position = back);
	},
	to: function(id) {
		this.links[this.position].removeClass('on');
		this._transition(this.slides, this.position, this.position = this.slides.indexOf(this.stage.getElement('#'+id)));
		this.links[this.position].addClass('on');	
	},
	
	auto: function() {
		(function(){
			this.links[this.position].removeClass('on');
			(this.position + 1 > this.slides.length-1) ? this._transition(this.slides, this.position, this.position = 0) : this._transition(this.slides, this.position, this.position += 1);
			this.links[this.position].addClass('on');
		}).bind(this).periodical(this.autotime);
    }
	
});




var preloadImgs = new Class({
	Implements:[Options,Events],
	options:{
		imgs: [],
		width: false,
		height: false	
	},
	initialize:function(options){
		this.setOptions(options);
		this.options.imgs.each(function(i){
			var imgObj = new Element('img',{
				'src': i.src,
				'width': i.width,
				'height': i.height
			});
		});
	}
});
/* end: slideshow scripting */



/* Click-through scripting */
var CreateClickThrough = new Class({
	Implements:[Options,Events],
	options:{
		stage: false,	// the slide stage/containing div
		slides: [] 	// the individual slide element
	},

	initialize:function(options){
		this.setOptions(options);
		this.stage = $(this.options.stage); if(!(this.stage)) return;
		this.addItems(this.options.slides);

        this.slides.each(function(slide, i) {
			slide.setProperty('id', 'slide00'+i)
			if(i == 0) return;
            slide.setStyle('opacity', 0);
        }, this);
		
        this.position = 0;
	},

	slides:[],
	
	addItems:function(items){
		$$(items).each(function(item){this.slides.include($(item));}, this);
	},
	
	addItem:function(item){
		this.addItems($splat($(item)));
	},
	
	_transition: function(stack,from, to) {
        var fromer = stack[from],tooer = stack[to];
		fromer.fade(0);
		tooer.fade(1);
    },
	
	next: function() {
		var next = this.position + 1 > this.slides.length - 1 ? 0 : this.position + 1;
		this._transition(this.slides, this.position, this.position = next);
	},
	back: function() {
		var back = this.position - 1 < 0 ? this.slides.length - 1 : this.position - 1;
		this._transition(this.slides, this.position, this.position = back);
	},
	to: function(id) {
		this._transition(this.slides, this.position, this.position = this.slides.indexOf(this.stage.getElement('#'+id)));
	}
	
});
/* end: Click-through scripting */







var newWindow = null;

var curHomeHero, homeTimeOutStart, homeTimeOut;	

window.addEvent('domready', function() {
	if($('docNavLoad')) $('docNavLoad').setStyle('display', 'inline');
});


window.addEvent('domready', function() {

	var navLength = $$("#topNav li").length;

	var iNav = 0;
	navLength.each(
		function( iNav )
		{
			$$("#topNav li")[iNav].onmouseover = function()
			{
				this.className += "doIeHover";
			}
			$$("#topNav li")[iNav].onmouseout=function()
			{
				this.className = this.className.replace(new RegExp("doIeHover\\b"), "");
			}
			iNav++
		}
	);
});


window.addEvent('domready', function() {
	$(document.body).addClass("js");
	if($("nav3"))
		{ docNav.init(); }

	if($('restaurant')) {
		($('yes').get('checked') != true) ? $('restaurant').setProperty('disabled', 'disabled') : $('visit-details').setStyle('display','block');
		($('restaurant').value == null || $('restaurant').value == '') ? $('restaurant').setStyles({'background':'gray'}) : $('restaurant').setStyles({'background':'#fff'});	
	}
	
	
	
	
	if($('over16yes') && $('over16yes').checked == false) {
		$$('#contact-form button','#contact-form input','#contact-form select','#contact-form textarea').each(function(field) {
			if(field.id != 'over16yes' && field.id != 'restaurant_id' && field.id != 'over16no' && field.id != 'restaurant') {
				field.setProperty('disabled','disabled');
				if(field.id != 'send' && field.getProperty('type') != 'radio') {
					field.setStyles({'background':'gray'});
				}
			}
		});
	} 

	if($('over16yes')) {
		$('over16yes').addEvent('click', function() {
			$$('#contact-form button','#contact-form input','#contact-form select','#contact-form textarea').each(function(field) {
				if(field.id != 'restaurant_id' && field.id != 'restaurant') {
					field.setProperty('disabled','');
				}
				if(field.id != 'send' && field.id != 'restaurant_id' && field.id != 'restaurant' && field.getProperty('type') != 'radio') {
					field.setStyles({'background':'#fff'});
				}
			});
		});
	};
	if($('choose-restaurant')) {
		$('choose-restaurant').addEvent('click', function() {
			$('restaurant').setStyles({'background':'#fff'});
			$('restaurant').setProperty('disabled','');
		});
	}

});

window.addEvent('domready', function() {
	
	if ($('link-providence')) {
		var back1 = $('i-back-1');
		var back2 = $('i-back-2');
		
		$('link-providence').addEvent('click', function(e) {
			// You often will need to stop propagation of the event
			e.stop();
			back1.fade(0);
			back2.fade(1);
			
			pageTracker._trackEvent('iView', 'mainIngrediantView', $('currentMenuItemName').get('value'));
			
			$$('form .nutriton-selectors select').each(function(selects){
				selects.setStyle('visibility', 'hidden');
			});
			$$('.nutrition-group-table thead th select').each(function(selects){
				selects.setStyle('visibility', 'hidden');
			});			
			sIFR.replace(fsalbert, {
				selector: 'h2.generic',
				css: [
				'.sIFR-root { font-size:24px; font-weight:normal; color:#ffffff; }'
				],
				wmode: 'transparent'
			});
		});
	
		$('link-nutrition').addEvent('click', function(e) {
			// You often will need to stop propagation of the event
			e.stop();
			back1.fade(1);
			back2.fade(0);
			$$('form .nutriton-selectors select').each(function(selects){
				selects.setStyle('visibility', 'visible');
			});
			$$('.nutrition-group-table thead th select').each(function(selects){
				selects.setStyle('visibility', 'visible');
			});
			sIFR.replace(fsalbert, {
				selector: 'h2.generic',
				css: [
				'.sIFR-root { font-size:24px; font-weight:normal; color:#ffffff; }'
				],
				wmode: 'transparent'
			});
		});
	};
});

function toggleForm(){
$("qlist").setStyle("display","none");
	$("question").setStyle("display","block");
}
	
function postIncludeInit(){
	$$("dl a").setProperty('href','javascript://').each(function(el){
		el.addEvent("click",function(el){
			$$("dl dd").each(function(el){
				el.style.display = 'none';			  
			 });		
			$(this).getParent().getNext().style.display = 'block';
		});
	});	
	$$('.nav-1 .nav-1').each(function(elm) {	
		elm.addEvent("mouseover", function(){
					//this.getElement(".nav-2").setStyle("display","block");		
					//this.getElement(".nav-2").fade("in");				   
					//do fade in code here.
				});
							 
		});
}

function createCSS(selector, declaration) {
	// test for IE
	var ua = navigator.userAgent.toLowerCase();
	var isIE = (/msie/.test(ua)) && !(/opera/.test(ua)) && (/win/.test(ua));

	// create the style node for all browsers
	var style_node = document.createElement("style");
	style_node.setAttribute("type", "text/css");
	style_node.setAttribute("media", "screen"); 

	// append a rule for good browsers
	if (!isIE) style_node.appendChild(document.createTextNode(selector + " {" + declaration + "}"));

	// append the style node
	document.getElementsByTagName("head")[0].appendChild(style_node);

	// use alternative methods for IE
	if (isIE && document.styleSheets && document.styleSheets.length > 0) {
		var last_style_node = document.styleSheets[document.styleSheets.length - 1];
		if (typeof(last_style_node.addRule) == "object") last_style_node.addRule(selector, declaration);
	}
};



function validateform(){
 var lastname = $("last").value;
 var emailaddress = $("email").value;
 var postvalue = $("postcode").value;
 var commentvalue = $("comment").value;
 var pv = $("complaint").checked; 
 var postvalue = $("postcode").value;
 var yea = $("yes").checked;
 var nea = $("no").checked;

	 if (lastname == ""){
	 //$("message1").setStyle("display","block");
	 $("last").addClass("error");
	}
	 if (emailaddress == ""){
	 //$("message2").setStyle("display","block");
	 $("email").addClass("error");
	}
	 if (commentvalue == ""){
	 //$("message3").setStyle("display","block");
	 $("comment").addClass("error");
	}
	if (pv == true && postvalue == ""){
	$("postcode").addClass("error");
	}
	if (yea == false && nea == false){
	$("yesno").addClass("error");
	}
};

// SMS: This function replaces the look of all the checkboxes on the site with bespoke checkbox designs
window.addEvent('domready', function() {  


// SetUp default
	if( $('francise_cbx_1') )
	{
		$$("#transBut a").set("href", "javascript:void(0)");
		$$("#transBut a").set("target", "");
		
		$('transBut').addClass("transBut");
		$('transBut').setStyle("cursor", "default");
	}

	$$('label.check').each(function(e){ 

		var ec = e.firstChild;
		function check(el){
		    var tmp = (el.firstChild.checked)?"_on":"_off";
			var setThisClass;
			if (el.hasClass('tick')) {
				setThisClass = "check tick "+ ec.type + "_tick" + tmp;
			} else if (el.hasClass('cross')) {
				setThisClass = "check cross "+ ec.type + "_cross" + tmp;				
			} else if (el.hasClass('white')) {
				setThisClass = "check white "+ ec.type + "_white" + tmp;
			} else if (el.hasClass('brown')) {
				setThisClass = "check brown "+ ec.type + "_brown" + tmp;				
			} else {
				setThisClass = "check "+ ec.type + tmp;				
			};
			return setThisClass;
		}
		e.className = check(e);
		e.style.cursor = 'pointer';
		ec.style.display = 'none';
		 
		 
		e.addEvent('click',function()
		{
			var chi = this.firstChild;
			
            if(!chi.checked || chi.type != 'radio')	chi.checked = !chi.checked;
 
            if(chi.type != 'radio') this.className = check(this);
			else{$$('label.check').each(function(j){
            	    if(j.firstChild.type == 'radio') j.className = check(j);
	            });
	        }

			// SMS: This function is used on the 'About Us > Franchise > Apply' page to display the button for the application form if all the checkboxes are checked.
			if ($('francise_cbx_1'))
			{
				if (($('francise_cbx_1').getProperty('checked') == 1) && ($('francise_cbx_2').getProperty('checked') == 1) && ($('francise_cbx_3').getProperty('checked') == 1) && ($('francise_cbx_4').getProperty('checked') == 1) && ($('francise_cbx_5').getProperty('checked') == 1)) 
				{
					$('transBut').addClass("fullBut");
					$('transBut').removeClass("transBut");
					$$("#transBut a").set("href", "https://careers.peopleclick.com/careerscp/client_mcdonalds/franchisee/search.do");
					$$("#transBut a").set("target", "_blank");
					
				}
				else 
				{
					$('transBut').addClass("transBut");
					$('transBut').removeClass("fullBut");
					$$("#transBut a").set("target", "");
					$$("#transBut a").set("href", "javascript:void(0)");
				};
			};
		});
		
	});
});




// popup
window.addEvent('domready', function(){
    findPopUps();
	if($('accord_faq_wrap')) {
		var ing_accord = new Accordion($('accord_faq_wrap'), 'a.toggler', 'div.accord_ele', {
			alwaysHide:true, 
			display:null,
			onActive: function(toggler, element){ toggler.addClass('on'); },
			onBackground: function(toggler, element){ toggler.removeClass('on'); } 
		});
	};
});



function closeWin(){
	if (newWindow != null){
		if (!newWindow.closed) newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	closeWin();
		
	type = type.toLowerCase();
	
	if (type == "fullscreen"){
		strWidth = screen.availWidth;
		strHeight = screen.availHeight;
	}
	var tools="";
	if (type == "standard") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console" || type == "fullscreen") tools = "resizable,toolbar=no,location=no,scrollbars=yes,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}

function doPopUp(e) {
    //set defaults - if nothing in rel attrib, these will be used
    var t = "standard";
    var w = "780";
    var h = "580";
    //look for parameters
    attribs = this.rel.split(" ");
    if (attribs[1]!=null) {t = attribs[1];}
    if (attribs[2]!=null) {w = attribs[2];}
    if (attribs[3]!=null) {h = attribs[3];}
    //call the popup script
    popUpWin(this.href,t,w,h);
    //cancel the default link action if pop-up activated
    if (window.event) {
        window.event.returnValue = false;
        window.event.cancelBubble = true;
	} else if (e) {
        e.stopPropagation();
        e.preventDefault();
	}
}

function findPopUps() {
var popups = document.getElementsByTagName("a");
for (i=0;i<popups.length;i++)
	{
	if (popups[i].rel.indexOf("popup")!=-1)
		{
		// attach popup behaviour
		popups[i].onclick = doPopUp;
		// add popup indicator
		if (popups[i].rel.indexOf("noicon")==-1)
			{
			popups[i].style.backgroundImage = "url(pop-up.gif)";
			popups[i].style.backgroundPosition = "0 center";
			popups[i].style.backgroundRepeat = "no-repeat";
			popups[i].style.paddingLeft = "15px";
			}
		// add info to title attribute to alert fact that it's a pop-up window
		popups[i].title = popups[i].title + " [Opens in pop-up window]";
		}
	}
}

// Function used to pass back the value in the Restaurant Locator to the contact us form 
function postValue(macd_name, restid){
	//opener.document.f1.restaurant.value = $(macd_name).value;
	opener.document.f1.restaurant.value = macd_name;
	opener.document.f1.restaurant_id.value = restid;
	self.close();
}



function chooseit(){
	var sel = $('department');
	if (sel.options[sel.selectedIndex].value == 'sel1'){$('dept1').show(); $('dept2').hide();$('dept3').hide();$('dept4').hide();} 
	if (sel.options[sel.selectedIndex].value == 'sel2'){$('dept1').hide(); $('dept2').show();$('dept3').hide();$('dept4').hide();}  
	if (sel.options[sel.selectedIndex].value == 'sel3'){$('dept1').hide(); $('dept2').hide();$('dept3').show();$('dept4').hide();}  
	if (sel.options[sel.selectedIndex].value == 'sel4'){$('dept1').hide(); $('dept2').hide();$('dept3').hide();$('dept4').show();} 
}

window.addEvent('domready', function() {
	$$('.showrange label")').each(function(rangeChange) {
		rangeChange.addEvent('click',function(e) {
			e.stop();
			var selectRange = this.getElement('input[type=radio]').get('value');
			$$('.gda','.gda_head').setStyle('display',(selectRange == 'gml' ? 'none' : 'block'));
			$$('.gml','.gml_head').setStyle('display',(selectRange == 'gml' ? 'block' : 'none'));
		});
	});
});

function getIndicator(elem) {
    var ind = [elem.get('tag')];
    if (elem.get('id')) ind.push('id=' + elem.get('id'));
    if (elem.get('name')) ind.push('name=' + elem.get('name'));
    if (elem.get('rel')) ind.push('rel=' + elem.get('rel'));
    if (elem.get('text')) ind.push('text=' + elem.get('text'));
    if (elem.get('value')) ind.push('value=' + elem.get('value'));
    if (elem.get('class')) ind.push('class=' + elem.get('class'));
    return ind;
}

window.addEvent('mousedown',function(e) {
    if (pageTracker) pageTracker._trackPageview($$('h2.ihero').get('text') + '/click/' + getIndicator(e.target).join('/'));
});

