
    var sifr = {
      src: '/domains/broodzakelijk.nl/plugins/sifr3-r436/sifr.swf'
      ,ratios: [7, 1.32, 11, 1.31, 13, 1.24, 14, 1.25, 19, 1.23, 27, 1.2, 34, 1.19, 42, 1.18, 47, 1.17, 48, 1.18, 69, 1.17, 74, 1.16, 75, 1.17, 1.16]
    };


    sIFR.replace(sifr, {
      selector: '.shop_category_thumbs .box div.content div.bar'
		,wmode: 'transparent'
      	,css: [
		'.sIFR-root { text-align:center;line-height:130%; font-size:14px; color:#ffffff; }',
		'a { text-align:center;line-height:130%; font-size:14px; color:#ffffff; text-decoration:none; }',
		'a:hover { color:#000000; }',
      ]
    });
    sIFR.replace(sifr, {
      selector: '#left h2'
		,wmode: 'transparent'
      	,css: [
		'.sIFR-root { text-align:left;line-height:130%; font-size:14px; color:#000000; }',
		'a { text-align:left;line-height:130%; font-size:14px; color:#000000; text-decoration:none; }',
		'a:hover { color:#8FC73E; }',
      ]
    });
    sIFR.replace(sifr, {
      selector: '#right h2'
		,wmode: 'transparent'
      	,css: [
		'.sIFR-root { text-align:left; font-size:21px;line-height:130%; color:#000000; }',
		'a { text-align:left; font-size:21px;line-height:130%; color:#000000; text-decoration:none; }',
		'a:hover { color:#8FC73E; }',
      ]
    });
	sIFR.replace(sifr, {
      selector: '.onsale_items_module div.item div.overlay div.price'
		,wmode: 'transparent'
      	,css: [
		'.sIFR-root { text-align:center; font-size:25px;line-height:100%; color:#ffffff; }',
		'a { text-align:left; font-size:25px;line-height:100%; color:#ffffff; text-decoration:none; }',
		'a:hover { color:#8FC73E; }',
      ]
    });


// You probably want to switch this on, but read <http://wiki.novemberborn.net/sifr3/DetectingCSSLoad> first.
//   sIFR.useDomLoaded = false;
    sIFR.useStyleCheck = true;
	sIFR.activate(sifr);



//make uniqID
var vuid=0;
var uid = function(){
	return vuid++ ;
}

//emulate popup function...
var popWindow = function(u,w,h,popEl){
	if(!popEl){
		e = u.substring(u.lastIndexOf('.')+1).toLowerCase();
		if(e == 'png' || e == 'gif' || e == 'jpg')
			popEl = $("<div class=\"popWindowDiv\" style=\"display:block;\"><img src=\""+ u +"\" width=\"" + w + "\" height=\"" + h + "\" border=\"0\" /></div>",{overlay:20});
		else
			popEl = $("<div class=\"popWindowDiv\" style=\"display:block;\"><iframe src=\""+ u +"\"  width=\"" + w + "\" height=\"" + h + "\" border=\"0\" frameborder=\"0\"></iframe></div>",{overlay:20});
	}
	popEl.modal({
			onOpen: function (dialog) {
						dialog.data.addClass('alert');
						dialog.container.css('height','auto');
						dialog.overlay.fadeIn('normal', function () {
							dialog.container.show('normal', function () {
								dialog.data.slideDown('normal'); // See Other Notes below regarding
														   // data display property and
														   // iframe details
							});
						});
					},
			onClose: function (dialog) {
						dialog.data.slideUp('normal', function () {
						  dialog.container.hide('normal', function () {
							dialog.overlay.fadeOut('normal', function () {
							  $.modal.close(); // must call this to have SimpleModal
											   // re-insert the data correctly and
											   // clean up the dialog elements
							});
						  });
						});
					}
	});
	$("#modalContainer").css('width',w).css('margin-left',(w / 2) * -1)
	if(h)
		$("#modalContainer").css('height',h);
	else
		h = $("#modalContainer").height();
	$("#modalContainer").css('margin-top',(h / 2) * -1);
	$("#modalContainer").css('width',w).css('margin-left',(w / 2) * -1);
	//.css('height',h).css('margin-top',(h / 2) * -1); 
}



var cacheButtonImage = function(o,u,h){
	var obj = o;
	var noHover = h;
	var img = new Image();
	$(img).css('border',0).addClass('buttonImg').load(function(){
		obj.html($(this));
		if(obj.hasClass('current_buttonID')){
			s = obj.children('.buttonImg:eq(0)').attr('src');
			obj.children('.buttonImg:eq(0)').attr('src',s + '&down=1');
			
			obj.parents('li').children('a').each(function(){
				s = $(this).children('.buttonImg').attr('src');
				$(this).children('.buttonImg').attr('src',s + '&down=1');
			});
		}
		if(!noHover){
			obj.hover(
				function(){
					if(!$(this).children('.buttonImg').attr('origSrc'))
						$(this).children('.buttonImg').attr('origSrc',$(this).children('.buttonImg:eq(0)').attr('src'));
		
					s = $(this).children('.buttonImg').attr('origSrc');
					$(this).children('.buttonImg').attr('src',s + '&over=1');
				},
				function(){
					s = $(this).children('.buttonImg').attr('origSrc');
					$(this).children('.buttonImg').attr('src',s);
				}
			);
		}
	}).attr('src',u);
}

var foundOnloadAlerts = new Array();
var alert = function(str){
	foundOnloadAlerts[foundOnloadAlerts.length] = str;
}


$(document).ready(function(){

	$(window).resize(function(){
	    $("#body-background").ezBgResize();
		h = $(window).height() - $('#container').height() - $('#footer').height() + 30 + $('#footer').height();
		if(h < 150)
			h = 150;
		$('#footer').height(h);
	});
	$(window).trigger('resize');

	//remove space/break in category listing
	$('ul.shop_categories a').removeClass('clear');

	//hide blank br
	$(".article .content .module_contents,#left > .module_contents").each(function(){
		if($(this).prev('br').length == 1){
			$(this).prev('br').remove();
		}
	});


	/* Image adjustments */
	$("img[align='left']").css('margin-right','15px');
	$("img[align='right']").css('margin-left','15px');

	/* Menu adjustments */
	$(".shop_categories_module > ul > li, #menu > ul > li").each(function(){
		//change main
		t = $(this).children('a').text();
		if(t){
			i = $(this).parents('.shop_categories_module').length;
			cacheButtonImage($(this).children('a'),'/domains/broodzakelijk.nl/generate/button.php?' + (i ? 'sub=true&' : '') + 'text=' + escape(t));
		}
	});
	//show submenu on hover
	$("#menu ul li").hover(
		function(){
			i = $(this).children('ul:eq(0)');
			if(i.is(":hidden"))
				i.show();
		},
		function(){
			i = $(this).children('ul:eq(0)');
			if(i.is(":visible"))
				i.hide();
		}
    );
	
	if($(".shop_category_thumbs div.box").length){
		$(".shop_category_thumbs div.box").click(function(){
			self.location.href = $(this).find('a:eq(0)').attr('href');
		});
	}
	
	if($(".onsale_items_module").length){
		$(".onsale_items_module div.item").click(function(){
			self.location.href = $(this).find('a:eq(0)').attr('href');
		});
	}
	
	
	//change store
	if($('.store_module').length){
		
		$('.store_module .listing div.article').each(function(){
			if($.trim($(this).find('div.title').text()) == $.trim($(this).find('span.article').text())){
				$(this).find('span.article').remove();
			}
		});

		//add submit button to list.
		$('.store_module .listing div.article:eq(0)').parents('form:eq(0)').append('<div class="listing_bottom"><input name="cart" type="submit" class="submit" value="PLAATS IN WINKELWAGEN" /></div>');
		$('.store_module .item_details div.prices').after('<div class="listing_bottom"><input name="cart" type="submit" class="submit" value="PLAATS IN WINKELWAGEN" /></div>');

		//change priceline layout
		if($('.store_module .listing div.article:eq(1) div.price_line').length > 1){
			$('.store_module .listing').addClass('more');
			
			//make from pricelines a head for the listing.
			listing_head = $('.store_module .listing div.article:eq(1) div.prices').clone();
			listing_head.addClass('listing_head').find('div.ui').remove()
			$('.store_module .listing .listing_header').after(listing_head);
			
			if($('.store_module .listing .listing_header .price_line').length < 6){
				$('.store_module .listing div.prices').width($('.store_module .listing div.article:eq(1) .price_line:eq(0)').outerWidth() * $('.store_module .listing div.article:eq(1) .price_line').length);
			}
			
			$('.store_module .listing div.article div.price_line span.amount .input[value=""]').val('0').focus(function(){
				if($(this).val() == 0)
					$(this).val('');
			});
			

			sIFR.replace(sifr, {
				selector: '.store_module .listing.more .article .title'
				,wmode: 'transparent'
				,css: [
					'.sIFR-root { text-align:left; font-size:12px;line-height:100%; color:#000000; }',
					'a { text-align:left; font-size:12px;line-height:100%; color:#000000; text-decoration:none; }',
					'a:hover { color:#8FC73E; }',
				]
				,onReplacement: function(fi) {
					// Movie has been replaced
					o = $('#' + fi['id']);
					h = o.height();
					if(h > o.parents('.article:eq(0)').find('div.price_line:eq(0) :input').height() - 5){
						o.parents('.article:eq(0)').find('div.price_line :input').height(h - 5);
					}
				}
			});
		}else{
			$('.store_module .listing').addClass('less');

			sIFR.replace(sifr, {
				selector: '.store_module .listing .article .title'
				,wmode: 'transparent'
				,forceSingleLine: true
				,css: [
					'.sIFR-root { text-align:left; font-size:14px;line-height:100%; color:#000000; }',
					'a { text-align:left; font-size:14px;line-height:100%; color:#000000; text-decoration:none; }',
					'a:hover { color:#8FC73E; }',
				]
			});
		}
	}

	//change all popups...
	var img = new Array();
	$(".article a").each(function(){
		i = 0;

		//change all onclick popups
		if($(this).attr('onclick')){
			i = $(this).attr('onclick').toString().indexOf("dow.open(this.href,");

			if(i){
				w = 640;
				h = 480;
				
				u = $(this).attr('href');
				e = u.substring(u.lastIndexOf('.')+1).toLowerCase();
				
				if(e == 'png' || e == 'gif' || e == 'jpg'){
					var id = 'popwinlink_' + uid();
					$(this).attr('id',id);

					img[id] = new Image();
					img[id].onload = function(){
						img[id].onload = null;
						w = img[id].width;
						h = img[id].height;
	
						$("a#" + id).attr('onclick',"").addClass('popWindowLink').attr('href',"javascript:popWindow('" + u + "'," + w + "," + h + ");");
					}
					img[id].src = u;
				}else{
					c = $(this).attr('onclick');
	
					h = c.substring(c.indexOf('height=') + 7);
					h = h.substring(0,h.indexOf(','));
	
					w = c.substring(c.indexOf('width=') + 6);
					w = w.substring(0,w.indexOf(','));
	
					$(this).attr('onclick',"").addClass('popWindowLink').attr('href',"javascript:popWindow('" + u + "'," + w + "," + h + ");");				
				}
			}

		//change all movie files
		}else if($(this).attr('href') && $(this).attr('href').match(/.(flv|FLV)$/)){
			//get filename...
			u = $(this).attr('href').match(/(\/db\/.*.(flv|FLV)$)/)[1];
			$(this).addClass('popWindowLink').attr('href',"javascript:popWindow('/domains/broodzakelijk.nl/video.php?file=" + u + "',320,260);");		
		}
	});
	
	//change the stupid HR behavour of IE...
	if($.browser.msie){
		$("#content hr").wrap("<div class=\"hr\"></div>");
		$("#content hr").css('display','none');
	}

	//kill MS word stuff!
	$(".MsoNormal,.MsoNormal *").removeAttr('style');

	//change submits
	$('input.submit').each(function(){
		$(this).wrap('<span class="' + $(this).attr('class') + '"><span></span></span>');
	});

	if($('strong.error').length){
		$('strong.error').each(function(){
			foundOnloadAlerts[foundOnloadAlerts.length] = $(this).html();
		});
	}

	//kill empty titles and articles
	$(".article,.title").each(function(){
		if(!$.trim($(this).text()) && !$(this).find('img,object,embed').length){
			$(this).remove();
		}
	});
	
	//my own alert...
	alert = function(str){
		popWindow('',300,'',$('<div id="alert clear"><span class="string">' + str + '</span></div>'));
	}
	//show all found alerts
	if(foundOnloadAlerts.length > 0){
		$.each(foundOnloadAlerts,function(){
			alert(this);
		});
	}
});

