var $chk = function(obj){
    return !!(obj || obj === 0);
};
if (!console || !console.log) {
    var console = {};
    console.log = function(){
    }
}

var $chk = function(obj) {
	return !!(obj || obj === 0);
};

window.addEvent('domready', function(){
	// ajax preferred store
    //gam.showMyLocation();
    if (gam.Tabs) {
    	gam.Tabs.Control();
    }

    //slide boxes
    if (document.getElementById("info-section")) {
    	var _open = -1;
        var items = $$('#info-section .title');
        var slide = $$('#info-section .slide');
        slide.each(function(el, i){
            slide[i].setStyles({
                "display": "block"
            });
            slide[i].setStyles({
                "margin-bottom": -slide[i].getHeight()
            });
            if (slide[i].className.indexOf("active") != -1) {
                slide[i].setStyles({
                    "margin-bottom": 0
                });
                _open = i;
            }
        });
        items.each(function(el, i){
            items[i].addEvent('mouseover', function(){
                if(_open != i){//skip concurrent onmouseover's for same item.
	            	if (slide[i].getStyle("margin-bottom").toInt() != 0 ) {
	                    if(_open > -1) {
	                    	slide[_open].tween("margin-bottom", -slide[_open].getHeight());
	                    }
	                    slide[i].tween("margin-bottom", 0);
	                    _open = i;
	                }
	                else {
	                    slide[i].tween("margin-bottom", -slide[i].getHeight());
	                }
	            }
            });
        });
    }
    //set li height bouwmarkt search
    var maxHeight = 0;
    var container = $$(".hor-search-results")[0];
   	if(container != null) {
	    var pointers = container.getElements(".onclickpointer");
	   	pointers.each(function(el){
	    	if(el.getSize().y > maxHeight){
	    		maxHeight = el.getSize().y;
	    	}
	    })
	    if(maxHeight > 0) {
	       	pointers.each(function(el){
	       		el.setStyle("height", maxHeight);
	        })
	    }
   	}

   	var content = $$('#content')[0];
   	if(content) {
   		content.getElements('.inform-box').each(function(el){
   			try {
   			var span = el.getElement('span');
   			var div = el.getElement('.text-bar');
   			var size = div.getSize();
   			if((size.y - 36) > 0){
   				span.setStyles({
   					"margin-bottom": (size.y - 36) + "px"
   				});
   			}
   			}
   			catch(e){}
   		});
   	}

	/* Fix IE7/6 CSS focus event */
	var els = document.getElementsByTagName("INPUT");
	for (var i = 0; i < els.length; i++) {
	    $(els[i]).addEvent('focus', function() {
		this.addClass("focus");
	    });
	    $(els[i]).addEvent('blur', function() {
		this.removeClass("focus");
	    });
	}
});

function openPopUp(params){
    var popup = $('karwFLP');
    if (!popup) {
        var shadow = $('karwFLPshadow');
        if (!shadow) {

			var shieldTag = "iframe";
			if($chk(params['noshield']) && (params['noshield'] == true || params['noshield'] == 'true')) {
				shieldTag = "div";
			}

            shadow = new Element(shieldTag, {
                'id': 'karwFLPshadow',
                'name': 'karwFLPshadow',
                'frameborder': 0
            });
            $(document.body).grab(shadow);

			if(shieldTag == 'iframe') {
	            window.frames["karwFLPshadow"].document.open();
	            window.frames["karwFLPshadow"].document.write("<html><body style='background-color:\"#000\"'></body></html>");
	            window.frames["karwFLPshadow"].document.close();
			}

            window.addEvent('resize', function(){
                shadow.setStyle('height', document.body.scrollHeight + 'px');
				shadow.setStyle('width', '100%');
            });
			window.fireEvent('resize');
        }


        popup = new Element('div', {
            'id': 'karwFLP',
            'html': '<div class="popup-holder"><div class="title"><a class="close" href="#">sluiten</a><h3></h3></div><div class="popup-content"></div></div>'
        });
        popup.getElement('a.close').onclick = function(){
            popup.hide()
            return false;
        }
        /*
        window.addEvent('resize', function(event){

        	var hViewport = (window.innerHeight || document.documentElement.clientHeight) -40;
			//alert(hViewport );
        	popup.getElement('.popup-holder').setStyle('width', document.body.scrollWidth + 'px');
        	popup.getElement('.popup-holder').setStyle('height', hViewport + 'px');
        	popup.getElement('iframe').setStyle('width', document.body.scrollWidth + 'px');
        	popup.getElement('iframe').setStyle('height', hViewport + 'px');
        	popup.centerV({
                animate: false
            });
        });
        */

        popup.setContent = function(strTitle, content){
            popup.getElement(".title h3").set("text", strTitle);
            popup.getElement(".popup-content").empty().grab(content);
           
            if($chk(popup.getElement("iframe")) && popup.getElement("iframe").src.indexOf("/turnpages/")>-1){
            	var w = popup.getElement("iframe").getSize().x;
            	
                popup.setStyles({
                	width: w
                });
        	}
        	else{
                popup.setStyles({
            		width: popup.getElement(".popup-content").getSize().x
                });
        	}
        }
        popup.show = function(){
            popup.setStyles({
                display: 'block'
            });
            shadow.setStyles({
                display: 'block',
                opacity: 0
            });
            shadow.fade(0.6)
        }
        popup.hide = function(){
            popup.setStyle('display', 'none');
            shadow.setStyle('display', 'none');
        }


        popup.centerV = function(params){
            var hPopup = params.animate ? params.futureH : popup.getSize().y;
            var hViewport = window.innerHeight || document.documentElement.clientHeight;
            var scrollTopViewport = $(document.body).getScroll().y;
            var newTop = Math.round(scrollTopViewport + Math.max(0, 0.5 * (hViewport - hPopup)));
            if (params.animate) {
                popup.tween("top", newTop);
            }
            else {
                popup.setStyle("top", newTop)
           }
        }
        popup.centerH = function(){
            popup.setStyles({
                marginLeft: parseInt(-0.5 * popup.getElement(".popup-content").getSize().x, 10)
            })
        }
        $(document.body).grab(popup);

        new Drag(popup, {
            handle: popup.getElement(".title"),
            modifiers: {
                'x': 'margin-left',
                'y': 'top'
            }
        });

    }
    var autoresize = true;
    
    if(params.contenttype == 'iframe' && params.frameurl.indexOf("/turnpages/")>-1){
    	//deze code is voor SiteCatalyst
    	if($chk(wa.setFolder)){
    		wa.setFolder();
    	}//Einde code voor SiteCatalyst.
    	autoresize = false;	
    }
    
    switch (params.contenttype) {
        case "iframe":
        	if(params.stepimage){
        		var image = new Asset.image($('stepimage').src);

        		params.frameheight = image.height + 50;
        		params.framewidth = image.width + 50;
        		params.frameurl =  $('stepimage').src;

        	}
            var iframe = new IFrame({
                //src: Browser.Engine.webkit?params.frameurl:"javascript:document.open();document.write(\"<html><body style='margin:0px;text-align:center'><image src='" + gam.loadImg.src + "'/></body></html>\");document.close();document.location.href='" + params.frameurl + "'",
                src: params.frameurl,
            	frameborder: "false",
                scrolling: params.frameheight ? "auto" : "no",
                styles: {
                    height: (params.frameheight ? params.frameheight : 20) + "px",
                    width: (params.framewidth ? params.framewidth : 600) + "px",
                    border: '0px solid #fff',
                    overflow: params.frameheight ? "auto" : "hidden"
                },
                events: {
                    load: function(){
                		//use try/catch to avoid "Permission denied" js-error in case of opening the folder overlay.
	                	try {
	                		var innerBody = Browser.firefox ? $(iframe.contentDocument.body) : $(iframe.contentWindow.document.body);
	                	} catch (exception) {}//do nothing
                        if (!params.frameheight && !iframe.containerHeightInitialized) {
                            var hContent = Browser.firefox ? iframe.contentDocument.body.offsetHeight : iframe.contentWindow.document.body.scrollHeight;
							// Adjust width if needed
							if(autoresize && innerBody.getFirst() && !params.frameWidth && innerBody.getFirst().getStyle('width') != 'auto' && !innerBody.getFirst().getStyle('width').contains('%')) {

								var wContent = innerBody.getFirst().getSize();
								var ieSize = window.ie ? (innerBody.getFirst().getStyle('padding-left').toInt() + innerBody.getFirst().getStyle('padding-right').toInt()) : 0;
								// var allSize = innerBody.getFirst().getStyle('margin-left').toInt() + innerBody.getFirst().getStyle('margin-right').toInt();
								// // console.log(innerBody.getFirst().getStyle('margin-left').toInt());
								// allSize += innerBody.getStyle('margin-left').toInt() + innerBody.getStyle('margin-right').toInt();
								//
								// allSize += innerBody.getStyle('padding-left').toInt() + innerBody.getStyle('padding-right').toInt();
								// alert(allSize);
								// wContent.x +=  allSize;
								// wContent.x += ieSize;

								// alert(wContent.x)

								iframe.setStyle('width', wContent.x);
								popup.setStyle('width', wContent.x);
							    popup.centerH({animate: true});
							}

							iframe.tween('height', hContent);

                            popup.centerV({
                                animate: true,
                                futureH: (hContent + 50)
                            });

                            //add the close function to any elements within the iframe with the class closebutton
                            var closeButton = innerBody.getElement('.closebutton');
                            if(closeButton){
                            	closeButton.onclick = function(){
                            		popup.hide()
                            		return false;
                            	}
                            }
                        }
                    }
                }

            })
            var content = iframe;
            break;
    }
    popup.show();
    popup.setContent(params.popuptitle, content)
    popup.centerH();
    popup.centerV({
        animate: false
    });
    return false;
}

function ieHover(){
    var nav = document.getElementById("table-b");
    if (nav) {
        var nodes = nav.getElementsByTagName("tr");
        for (var i = 0; i < nodes.length; i++) {
            nodes[i].onmouseover = function(){
                this.className += " hover";
            }
            nodes[i].onmouseout = function(){
                this.className = this.className.replace(" hover", "");
            }
        }
    }
    $$('.vscroll-slider').each(function(_el){
        _el.onmouseover = function(){
            _el.addClass('hover');
        }
        _el.onmouseout = function(){
            _el.removeClass('hover');
        }
    });
}

function initDrop(){
    /*--- compte-freelance popup js ---*/
    var _hold = $$('.productplacement .sub-block')[0];
    if (_hold) {
        var _btn = _hold.getElement('.drop');
        var _box = _hold.getElement('.holder .slide-block');
        if (_btn && _box) {
            var _f = false;
            _box.moo = new Fx.Tween(_box, {
                duration: 400,
                link: 'cancel',
                'onComplete': function(){
                    if (!_f)
                        _box.getParent().setStyle('height', '0');
                }
            });
            _btn.onclick = function(){
                if (_f) {
                    var _h = _box.offsetHeight;
                    _hold.removeClass('active');
                    _box.moo.start('margin-top', -_h);
                    _f = false;
                }
                else {
                    var _h = _box.offsetHeight;
                    _hold.addClass('active');
                    _box.setStyle('margin-top', -_h);
                    _box.getParent().setStyle('height', 'auto');
                    _box.moo.start('margin-top', 0);
                    _f = true;
                }
                return false;
            }
        }
    }
}

if (window.addEventListener) {
    window.addEventListener("load", initDrop, false);
}
else
    if (window.attachEvent && !window.opera) {
        window.attachEvent("onload", initDrop);
        window.attachEvent("onload", ieHover);
    }


gam.Tabs = {}
gam.Tabs.vars = {
    selectedTab: null,
    selectedContent: null
}

gam.Tabs.Control = function(){
    var tabAreas = $$('.tab-section');

    for (i = 0; i < tabAreas.length; i++) {
        var singleTabArea = tabAreas[i];

        var tabs = singleTabArea.getElements('ul.tabset a.tab');
        for (i = 1; i <= tabs.length; i++) {
            var tabItem = tabs[i - 1];
            if (i == 1) {
                gam.Tabs.vars.selectedTab = tabItem;
                gam.Tabs.vars.selectedTab.getParent().addClass("active");
                gam.Tabs.vars.selectedContent = $('tab-' + i);
                gam.Tabs.vars.selectedContent.addClass("display");
            }
            tabItem.addEvent('click', gam.Tabs.ShowTabContent.bindWithEvent(window, [tabItem, i]));

        }
    }
}
gam.Tabs.ShowTabContent = function(e, tabItem, counter){
    var tabContentPanel = $('tab-' + counter);


    gam.Tabs.vars.selectedTab.getParent().removeClass("active");
    tabItem.getParent().addClass("active");
    gam.Tabs.vars.selectedTab = tabItem;

    gam.Tabs.vars.selectedContent.removeClass("display");
    tabContentPanel.addClass("display");
    gam.Tabs.vars.selectedContent = tabContentPanel;
}

gam.setNumStoresOpenSunday = function(){
	new Request.JSON({
		url: gam.context + '/store/get_num_stores_open_sunday?random='+Math.random(),
        noCache:true,
        method: 'get',
        onSuccess: function(jsonResponse){
			$$('#noPreferredStore .numStoresOpenSunday').set('html', jsonResponse.numStoresOpenSunday);
		}
	}).send();
}


gam.showMyLocation = function(){
	if ($('preferredStore')) {
	    new Request.JSON({
	        url: gam.context + '/store/get_preferred_store?random='+Math.random(),
	        noCache:true,
	        method: 'get',
	        onSuccess: function(jsonResponse){
	        	var dow = new Date().getDay();
	        	var showPreferred=false;
	        	
	        	// Switch day +1 if time is later than 21.00 hours
	        	if (dow==0 && (new Date().getHours() >= 21)) dow += 1;
	        	
	        	if (jsonResponse.store) {
		    		if(dow > 0 || (dow == 0 && jsonResponse.store.openingHoursSunday)){//show preferred sunday open
			    		$('noPreferredStore').setStyle("display", "none");
			    		$('preferredStore').setStyle("display", "block");
			    		showPreferred=true;
			    	} else {//show other sundayopenstores.
			    		$('preferredStore').setStyle("display", "none");
			    		$('noPreferredStore').setStyle("display", "block");
			    	}
		    	} else {
		    		$('preferredStore').setStyle("display", "none");
		    		$('noPreferredStore').setStyle("display", "block");
		    	}

		    	if (showPreferred) {
		    		var store = jsonResponse.store;
		    		$$('#preferredStore #storeTitle').set('html', 'GAMMA ' +store.name);
		    		$$('#preferredStore .storeLink').set('href', gam.context+store.url);
		    		var openingHours='';
	    			var dayName='Other';
		    		if(dow == 0) {
	    				dayName='Sunday';
		    			if(store.openingHoursSunday){
		    				openingHours = store.openingHoursSunday;
		    				$$('.openinghourstxt.Sunday').setStyle('display','block');
		    			}
		    		}else{
		    			var openingsHoursArray;
		    			$$('.openinghourstxt.other').setStyle('display','block');
		    			if(store.openingHoursSunday){
		    				openingsHoursArray = gam.getOpeningHours(store.openingHoursSunday);
		    				$$('#sundayStart').set('html',openingsHoursArray[0]);
		    				$$('#sundayEnd').set('html',openingsHoursArray[1]);
		    			}
		    			else{
		    				$$('.openinghourstxt .satday').addClass('right');
		    				$$('.openinghourstxt .sunday').setStyle('display','none');
		    			}
		    			openingsHoursArray = gam.getOpeningHours(store.openingHoursSaturday);
		    			$$('#satdayStart').set('html',openingsHoursArray[0]);
	    				$$('#satdayEnd').set('html',openingsHoursArray[1]);

		    			openingHours = store.openingHoursWeekdays;
		    		}
		    		//do not display date and opening times when the store is closed
		    		if(openingHours != '') {
		    			var openingsHoursArray = gam.getOpeningHours(openingHours);
		    			var fromEl = new Element('div', {
		    				'class': 'from',
		    				'html': openingsHoursArray[0]
		    			});
		    			var two="";
		    			if(openingsHoursArray[0]>9){two="2";}
		    			var tillEl = new Element('div', {
		    				'class': 'till'+two,
		    				'html': openingsHoursArray[1]
		    			});
		    			$('openingTimes'+dayName).adopt(fromEl, new Element('div', {'class': 'arrow'+two}), tillEl);
		    		}
		    		
		    		if($$('#preferredStore #storeTitle').getHeight() > 25){
			    		$$('.promohome .txt').each(function(el){
			    			el.setStyle('height',125);
			    		});
		    		}
		    	}

		    },
	        onFailure: function(){
	        }
	    }).send();
	}
}
gam.getOpeningHours = function(hoursStr){
	var result=Array();
	var openingsHoursArray = hoursStr.split('-');
	var fromSplit = openingsHoursArray[0].split('.');
	if (fromSplit[0].substr(0,1) == '0'){ fromSplit[0] = fromSplit[0].substr(1,1);}
	result[0]=fromSplit[0];
	var tillSplit = openingsHoursArray[1].split('.')
	result[1]=tillSplit[0];
	return result;
}
gam.printLists = function(id){
	var noshow = $$(".info-bar")[0];
	noshow.addClass("dontprint");
	window.print();
	noshow.removeClass("dontprint");
}

gam.printCoupon = function(id){
	var noshow = $$(".visual-text")[0];
	noshow = noshow.getElement('p');
	noshow.addClass("dontprint");
	window.print();
}

gam.toggleHelp = function(element){
	var parent = $(element).getParent();
	var messageBox = $(parent).getElement('div.explain_text');
	var errorBox = parent.getElement('div.error_text');
	if(!messageBox.bolVisible){
		if(errorBox) {errorBox.setStyle("display","none")};
		messageBox.fade(0,1);
		messageBox.bolVisible = true;
	}
	else{
		if(errorBox) {errorBox.setStyle("display","block")};
		messageBox.fade(1,0);
		messageBox.bolVisible = false;
	}
}

gam.submitForm = function(el){
	var form = $(el).getParent("form");
	form.getElementById("event").set('value',el.id);

	if($chk(form.get('onsubmit'))) {
		gam.postAquimaForm(form, true);
	} else {
		form.submit();
	}

	return false;
}

gam.addClass = function(element, className){
	element.className = element.className + ' ' + className;
}

gam.removeClass = function(element, className){
	var classRegexp =  new RegExp(className, "g");
	element.className = element.className.replace(classRegexp, "");
}

gam.aquimapost = function(field){
	// field.form.parentNode.style.display='none';
	// document.getElementById('aquimaloading').style.display ='block';
	// field.form.submit();
	gam.postAquimaForm(field.form, false);
}
gam.postAquimaForm = function(target_form, moveToTop) {
	target_form = $(target_form);
	var action = target_form.action;

	var newAction = '';
	if($chk(action) && action !== null && action !== '') {
		newAction = action+"&view=Fragment";
	} else {
		newAction = "?view=Fragment";
	}
	target_form.set('send', {url: newAction, method: 'post', onComplete:gam.postAquimaFormCompleteHandler.bindWithEvent(window, [moveToTop])});
	target_form.send();

	// Disable form
	var f_elements = target_form.elements;
	for(var i=0;i<f_elements.length;i++) {
		var f_elm = $(f_elements[i]);
		f_elements[i].set('disabled', 'true');
	}
	return false;
}
gam.postAquimaFormCompleteHandler = function(newPageXML, moveToTop) {
	var tmpEl = new Element('div');
	tmpEl.set('html', newPageXML);
	tmpEl.getFirst().replaces($(document.body).getElement('.aquimapage'));

	if(moveToTop !== false) {
		var top = $('aquimatop');
		var coord = top.getCoordinates(document.body);
		window.scrollTo(coord.left,coord.top);
	}
}
gam.goRoute = function(storeURL){
	var address = $('route').value;
	if(address == ""){
		alert("vul wat in");
	}else{
		location.href=storeURL+"?addr="+address+"#routeplanner";
	}
}
gam.focusTextBox = function(inputElement){
	inputElement.focus();
	if(inputElement.value=='postcode of plaats'){
		inputElement.value='';
	}
}

gam.getSelectboxTextValue = function(id,index) {
	var select = document.getElementById(id);
	if (select) {
		if (!index) {
			index = select.selectedIndex;
		}

		return select.options[parseInt(index)].text;
	}

	return null;
}

window.checkRadiobutton = function(which) {
    if ($(which)) {
	$(which).set('checked', 'checked');
    }
}

window.addEvent('domready', function(){
	
	// Add class selected
	var arrayOfSelected = [
        $$('div.productitem div.borderbox'),
        $$('div.cartitem'),
        $$('div.promo:not(.promohome) div.borderbox'),
        $$('div.promo div.whitebox'),
        $$('span.btn input')
	];
	arrayOfSelected.each(function(single) {
		single.each(function(el) {
			el.addEvents({
				mouseenter: function(){
					el.addClass('selected');
				},
				mouseleave: function(){
					el.removeClass('selected');
				}
			});
		});
	});
	
	// Add onClick event on banners
	var arrayOfBannersWithEvents = [
	    $$('div.promo:not(.promohome) div.borderbox'),
	    $$('div.promo div.whitebox')
	];
	arrayOfBannersWithEvents.each(function(single) {
		single.each(function(el) {
			el.addEvents({
				mouseenter: function () {
					if (el.getElement('a')) {
						el.addEvent('click', function() {
							if(String(el.getElement('a').onclick).indexOf("openPopUp")>-1){
								el.getElement('a').onclick();
							}
							else if(el.getElement('a').target=="_blank") {
								window.open(el.getElement('a').getProperty('href'));
							}
							else {
								window.location.href=el.getElement('a').getProperty('href');
							}
						});
						el.setStyle('cursor', 'pointer');
					}
				},
				mouseleave: function() {
					el.removeEvents('click');
				}
			});
		});
	});
	
	
	// Add class active
	var arrayOfActive = [
         $$('span.btn input')
 	];
	arrayOfActive.each(function(single) {
 		single.each(function(el) {
 			el.addEvents({
 				mouseover: function(){
 					el.addClass('active');
 				},
 				mouseleave: function(){
 					el.removeClass('active');
 				}
 			});
 		});
 	});
	
	// Add class for each type of input
	$$('input').each(function(e) {
		switch (e.getProperty('type')) {
			case 'text':
				if (!e.hasClass('text'))
					e.addClass('text');
				break;
			case 'radio':
				if (!e.hasClass('radio'))
					e.addClass('radio');
				break;
			case 'checkbox':
				if (!e.hasClass('checkbox'))
					e.addClass('checkbox');
				break;
		}
	});
	
	// Input fields with blurring
	var arrayOfInputs = [
	    $$('div.search input.text'),
	    $$('div.inpage .cart-add input.text'),
	    $$('div.topnav div#cart .cart-add input.text')
	];
	arrayOfInputs.each(function(single){
		single.each(function(el) {
			var defaultValue = el.value;
			el.addEvents({
				focus: function() {
					el.addClass('focus');
					el.addClass('notempty');
				},
				blur: function() {
					el.removeClass('focus');
					el.removeClass('notempty');
					if (el.value == '')
						el.value = defaultValue;
				},
				click: function() {
					if(this.value == defaultValue)
						this.value = '';
				}
			});
		});
	});
	
	$$('div.nav ul ul li:nth-child(3n)').each(function(e) {
		e.addClass('last');
	});
	
	$$('div.wrapper').each(function(e) {
		//e.getElements('div.c2:even').each(function(e2) {
			//e2.addClass('clear');
		//});
		e.getElements('div.c2:nth-child(2n)').each(function(e2) {
			e2.addClass('last');
		});
		// 1e, 4e, 7e, 10e enz
		e.getElements('div.c3:nth-child(3n-2)').each(function(e2) {
			e2.addClass('clear');
		});
		// 3e, 6e, 9e, 12e enz
		e.getElements('div.c3:nth-child(3n)').each(function(e2) {
			e2.addClass('last');
		});
		// 1e, 5e, 9e, 13e enz
		e.getElements('div.c4:nth-child(4n-3)').each(function(e2) {
			e2.addClass('clear');
		});
		// 4e, 8e, 12e, 16e enz
		e.getElements('div.c4:nth-child(4n)').each(function(e2) {
			e2.addClass('last');
		});
		// 1e, 6e, 11e, 17e enz
		e.getElements('div.c5:nth-child(5n-4)').each(function(e2) {
			e2.addClass('clear');
		});
		// 5e, 10e, 15e, 20e enz
		e.getElements('div.c5:nth-child(5n)').each(function(e2) {
			e2.addClass('last');
		});
	});
	
	$$('div.graybox div.whitebox:last-child').each(function(e) {
		e.addClass('last');
	});
	
	// eerste li
	$$('ul li:first-child').each(function(e) {
		e.addClass('first');
	});
	
	// laatste li
	$$('ul li:last-child').each(function(e) {
		e.addClass('last');
	});
	
	$$('.whitebox.last').each(function(e) {
		e.addClass('whiteboxlast');
	});
	
	$$('.c2.last').each(function(e) {		
		e.addClass('c2last');
	});
	$$('.c3.last').each(function(e) {
		e.addClass('c3last');
	});
	$$('.c4.last').each(function(e) {
		e.addClass('c4last');
	});
	$$('.c5.last').each(function(e) {
		e.addClass('c5last');
	});
	
});
