// dropdown menu and prettyPhoto scripts for all pages

//ie7 shaize detect...
ie7=0;
jQ.each('a',function(){
	if (this!='a') ie7=1;
	else ie7=0;
});



function ftemplate() {
	jQ('#horiz-menu>ul.menu>li').first().addClass('first');
	jQ('#horiz-menu>ul.menu>li').addClass('lv1');
	jQ('#horiz-menu>ul.menu>li>ul>li').addClass('lv2');
	jQ('#horiz-menu>ul.menu>li>ul>li>ul>li').addClass('lv3');
	jQ('#horiz-menu li.lv1').each(function(){
		jQ(this).find('li.lv2').last().addClass('last');
	});
	jQ('#horiz-menu li.lv2').each(function(){
		lv3ta = jQ(this).find('li.lv3');
		jQ(lv3ta).first().addClass('first');
		jQ(lv3ta).last().addClass('last');
	});
	jQ('#horiz-menu li.lv2>ul').hover(
		function(){jQ(this).closest('li.lv2').addClass('inthesub');},
		function(){jQ(this).closest('li.lv2').removeClass('inthesub');}
	);
	jQ('#horiz-menu li.lv1>ul').hover(
		function(){jQ(this).closest('li.lv1').addClass('inthesub');},
		function(){jQ(this).closest('li.lv1').removeClass('inthesub');}
	);
	
	//probing for type of page...
	prdp = jQ('#bg>.bodyjr');
	if (jQ(prdp).hasClass('products-details')) single_products();
	else if (jQ(prdp).hasClass('single-recipe')) single_recipe();
	// downloads
	if (jQ(document.body).hasClass('mid10')) {
		i_headers_rend();
		dl_page();
	}
	//products root
	if (jQ(prdp).hasClass('pr-root')) pr_root(1);	
	
	// dealer reg form
	if (jQ(document.body).hasClass('mid226') || jQ(document.body).hasClass('mid253')) {
		jQ(document.body).addClass('mid226');
		drf();
	}
	//404
	if (jQ(document.body).hasClass('mid248')) {
		err404();
	}
	//Contact Us
	if (jQ(document.body).hasClass('mid5')) {
		contacts();
	}
	//Thank you 
	if (jQ(document.body).hasClass('mid250')) {
		thankyou();
	}
	
	// Search page...
	sprobe = jQ('.nice_body #vmMainPage > h3');
	if (sprobe.length>0 && (jQ.trim(jQ(sprobe).text())=='Browse' || jQ(sprobe).text().match(/^Search:/))) jQ(sprobe).addClass('srchh');
	
	if (jQ('.ihrend').length > 0) {
		hehml = '<div class="componentheading">'+jQ('td.contentheading').html()+'</div>';
		jQ('td.contentheading').removeClass('contentheading').html(hehml);
		i_headers_rend();
	}
	
}


function prph_init() {
	setTimeout(function(){
		pps = jQ('a[rel="prettyPhoto"]');
		if (pps.length<1) return false;
		jQ(pps).prettyPhoto();
		jQ(pps).click(function(){
			if (typeof(lightboxclickfix)=='function') lightboxclickfix(this);
			ppfragfix();
			setTimeout(function(){
				jQ('.pp_pic_holder.pp_default,.pp_overlay').not('.pp_ffix').addClass('pp_ffix').click(function(){
					ppfragfix();
				});
			},200);
		});
	},1000);
}

function ppfragfix() {
	setTimeout(function(){clearInterval(ppfragfixi)},1000);
	ppfragfixi = setInterval(function(){
		if (window.location.href.match(/#!prettyPhoto/)) {
			wst = jQ(window).scrollTop();
			window.location.href = window.location.href.replace(/#.*$/,'#');
			jQ(window).scrollTop(wst);
			clearInterval(ppfragfixi);
		}
	},150);
}

ipreps ='<img src="/templates/img/ddm-lv2.png" />';
ipreps+='<img src="/templates/img/ddm-lv3-all.png" />';
ipreps+='<img src="/templates/img/ddm-lv2-last.png" />';
ipreps+='<img src="/templates/img/menu-right.png" />';
ipreps+='<img src="/templates/img/menu-b.png" />';
ipreps+='<img src="/templates/img/menu-b-first.png" />';
ipreps+='<img src="/templates/img/dlitem-pdf.png" />';
ipreps ='<div class="iprewr">'+ipreps+'</div>';
function img_preload() {
	if(jQ('#top_wrap').length<1) return false;
	if(jQ('div.iprewr').length) { clearInterval(img_preload_i);	return false; }
	jQ('#top_wrap').before(ipreps);
}
img_preload_i = setInterval(function(){img_preload()},100);



ifontdir1 = '/templates/img/ifont/';
function i_headers_rend() {
	jQ('div.componentheading').each(function(){
		if (jQ(this).parent('td.contentheading').length>0) return 1;
		keeps = jQ(this).find('div.keep');
		if (keeps.length) jQ(this).after(keeps);
		
		htex = jQ(this).text().toLowerCase();
		htex = htex.replace(/[^\-a-z0-9 &,\.'!]/g,' ');
		htex = jQ.trim(htex.replace(/ {2,}/g,' '));
		ihtex = '';
		jQ.each(htex.split(''),function(){
			if (this==' ') ihtex+='</span><i>&nbsp; </i><span class="ift_word">';
			else if (this=='&') ihtex+='<img src="'+ifontdir1+'amp'+'.png" class="ift_'+'amp'+'" />';
			else if (this==',') ihtex+='<img src="'+ifontdir1+'comma'+'.png" class="ift_'+'comma'+'" />';
			else if (this=='.') ihtex+='<img src="'+ifontdir1+'dot'+'.png" class="ift_'+'dot'+'" />';
			else if (this=="'") ihtex+='<img src="'+ifontdir1+'apostr'+'.png" class="ift_'+'apostr'+'" />';
			else if (this=="-") ihtex+='<img src="'+ifontdir1+'dash'+'.png" class="ift_'+'dash'+'" />';
			else if (this=="!") ihtex+='<img src="'+ifontdir1+'exclm'+'.png" class="ift_'+'exclm'+'" />';
			else ihtex+='<img src="'+ifontdir1+this+'.png" class="ift_'+this+'" />';
		});
				
		jQ(this).css('visibility','visible').html('<span class="ift_wra"> <span class="ift_word">'+ihtex+'</span> </span>');
		if (keeps.length) jQ(this).append(keeps);
	});
}



function pr_cells() {
	
//	return;
	if (jQ('#bg>.bodyjr').hasClass('products-details')) return;
	
	jQ('#bg>.bodyjr').addClass('pr-cats');
	
	bpcons = jQ('div.browseProductContainer');
	
	if (bpcons.lenght<1) return;
	
	jQ(bpcons).append('<div class="p_sumr"></div><div class="p_sum"></div><div class="bottom-block"></div>')
	
	jQ(bpcons).each(function(){ 
		oj=this;
		jQ(oj).children('div.p_sum').prepend(jQ(oj).children('a.contentpagetitle,div.browseProductDescription'));
		jQ(oj).children('div.p_sumr').prepend(jQ(oj).find('div.browsePriceContainer,div.view_and_buy'));
		pdo = jQ(oj).find('div.p_sum>.browseProductDescription>div');
		jQ(pdo).html(jQ(pdo).html().replace(/<br[ \/]*>/gi,'<br>'));
		jQ(pdo).html(jQ(pdo).html().replace(/<br \/>[^a-z<>,\.]+<br \/>/gi,'<br><br>'));
		
		
		delemes = Array();
		rightelemes = Array();
		// !!! achtung !!!
		if (jQ(pdo).html().match(/<br>/)) delemes=jQ(pdo).html().split('<br><br>');
		else delemes=jQ(pdo).html().split('<BR><BR>');
	//	return 1;
	
		if (delemes[0].length<120) {
			jQ(pdo).html('<div class="bluedescr">'+delemes[0]+'</div><br><br>'+delemes[1]);
			if (delemes[2]) rightelemes = delemes[2].match(/<b[^>]*>[^<]*<\/b>([^<]*)/gi);
			if (rightelemes===null) rightelemes = Array();
			jQ(oj).children('div.p_sumr').prepend('<div class="rightelemes">'+rightelemes.join('<br>')+'</div>');
			jQ(oj).find('.rightelemes').contents().filter(function(){
				return this.nodeType!=1;
			}).wrap('<span class="nowrap new_wrap"/>');
		}
	});
	
	jQ('span.new_wrap').each(function(){
		jQ(this).html(jQ.trim(jQ(this).text())).before(document.createTextNode(" ")).after(document.createTextNode(" "));
	});
	
	jQ(bpcons).hover(
		function(){jQ(this).addClass('hover')},
		function(){jQ(this).removeClass('hover')}
	);
	
	//the next line should be gone somewhere in the future...
	jQ('.vmCatDesc > img').remove();
	jQ('.vmCatDesc').addClass('catdesc');
	
	jQ('.vmNavChildList>.VM_center_text').last().addClass('last');
	
	jQ('tr.VM_center_text>td>a.tu').each(function(){
		if (jQ(this).text().match(/Cutlass +Pro +Series +Grills/)) {
			jQ(this).css('background-image','url(/templates/img/cutlass-pro-btn.png)');
			jQ(this).addClass('suhe suh1').html('');
			jQ('.vmCatDesc').addClass('grills');
		}
		if (jQ(this).text().match(/Cutlass +Series +Grills/i)) {
			jQ(this).css('background-image','url(/templates/img/cutlass-btn.png)');
			jQ(this).addClass('suhe suh2').html('');
		}
		if (jQ(this).text().match(/Cutlass +Series +Grills/i)) {
			jQ(this).css('background-image','url(/templates/img/cutlass-btn.png)');
			jQ(this).addClass('suhe suh3').html('');
		}
		if (jQ(this).text().match(/Junior +Series +Grills/i)) {
			jQ(this).css('background-image','url(/templates/img/junior-btn.png)');
			jQ(this).addClass('suhe suh4').html('');
		}
		
		
		if (jQ(this).text().match(/Side +Burners/i)) {
			jQ(this).css('background-image','url(/templates/img/side-burners-btn.png)');
			jQ(this).addClass('suhe suh5').html('');
			jQ('.vmCatDesc').addClass('access');
		}
		if (jQ(this).text().match(/doors/i)) {
			jQ(this).css('background-image','url(/templates/img/doors-btn.png)');
			jQ(this).addClass('suhe suh6').html('');
		}
		if (jQ(this).text().match(/drawers/i)) {
			jQ(this).css('background-image','url(/templates/img/drawers-btn.png)');
			jQ(this).addClass('suhe suh7').html('');
		}
		if (jQ(this).text().match(/racks/i)) {
			jQ(this).css('background-image','url(/templates/img/racks-btn.png)');
			jQ(this).addClass('suhe suh8').html('');
		}
		if (jQ(this).text().match(/Beverage +Centers/i)) {
			jQ(this).css('background-image','url(/templates/img/beverage-centers-btn.png)');
			jQ(this).addClass('suhe suh9').html('');
		}
		if (jQ(this).text().match(/coolers/i)) {
			jQ(this).css('background-image','url(/templates/img/coolers-btn.png)');
			jQ(this).addClass('suhe suh10').html('');
		}
		if (jQ(this).text().match(/Trash +Containers/i)) {
			jQ(this).css('background-image','url(/templates/img/trash-containers-btn.png)');
			jQ(this).addClass('suhe suh11').html('');
		}
		if (jQ(this).text().match(/Refrigeration/i)) {
			jQ(this).css('background-image','url(/templates/img/refrigeration-btn.png)');
			jQ(this).addClass('suhe suh12').html('');
		}
		
		
		if (jQ(this).text().match(/Grill +Carts/i)) {
			jQ(this).css('background-image','url(/templates/img/grill-carts-btn.png)');
			jQ(this).addClass('suhe suh13').html('');
			jQ('.vmCatDesc').addClass('cacobu');
		}
		if (jQ(this).text().match(/Grill +covers/i)) {
			jQ(this).css('background-image','url(/templates/img/grill-covers-btn.png)');
			jQ(this).addClass('suhe suh14').html('');
		}
		if (jQ(this).text().match(/Infrared +Burners/i)) {
			jQ(this).css('background-image','url(/templates/img/infrared-burners-btn.png)');
			jQ(this).addClass('suhe suh15').html('');
		}		
		if (jQ(this).text().match(/Infrared +Burners/i)) {
			jQ(this).css('background-image','url(/templates/img/infrared-burners-btn.png)');
			jQ(this).addClass('suhe suh15').html('');
		}		
		if (jQ(this).text().match(/Rotisserie +Kits/i)) {
			jQ(this).css('background-image','url(/templates/img/rotisserie-kits-btn.png)');
			jQ(this).addClass('suhe suh16').html('');
		}		
		if (jQ(this).text().match(/Sinks/i)) {
			jQ(this).css('background-image','url(/templates/img/sinks-btn.png)');
			jQ(this).addClass('suhe suh17').html('');
		}		
		if (jQ(this).text().match(/Hoses +and +Regulators/i)) {
			jQ(this).css('background-image','url(/templates/img/hoses-and-regulators-btn.png)');
			jQ(this).addClass('suhe suh18').html('');
		}		
		if (jQ(this).text().match(/Grill +Liners/i)) {
			jQ(this).css('background-image','url(/templates/img/grill-liners-btn.png)');
			jQ(this).addClass('suhe suh19').html('');
		}		
		if (jQ(this).text().match(/Island +Vents/i)) {
			jQ(this).css('background-image','url(/templates/img/island-vents-btn.png)');
			jQ(this).addClass('suhe suh20').html('');
		}
		if (jQ(this).text().match(/Pre\-Made +Outdoor +Kitchens/i)) {
			jQ(this).css('background-image','url(/templates/img/pre-made-outdoor-kitchens-btn.png)');
			jQ(this).addClass('suhe suh21').html('');
		}
		if (jQ(this).text().match(/Grill +Insultating +Liners/i)) {
			jQ(this).css('background-image','url(/templates/img/grill-insultating-liners-btn.png)');
			jQ(this).addClass('suhe suh22').html('');
		}
	});
	
//	jQ('#vmMainPage>form[name="order"]').wrap('<div class="oformwr"/>');
}


