var mydeco_wl = {
	hash: null,
	ifr: document.createElement('iframe'),
	ifr_mess_reg: /mydeco_mess=(.+);/g, // regexp for message parsing
	
	ifr_attr: { // mydeco iframe attributes
		id: 'mydeco_iframe', name: 'mydeco_iframe', 
		marginWidth: '0', marginHeight: '0'
	},
	ifr_style: { // mydeco iframe styles
		width: '100%', height:'700px', border: '0'
	},
	
	extend: function(base,extender){ for(var i in extender) base[i]=extender[i]; return base; },
	
	init: function() {
		var query = /[?&]query=([^&]*)/.exec(location.search);
		var top10 = /[?&]page=([^&]*)/.exec(location.search);
		var guid = /[?&]guid=([0-9a-f]{40})/.exec(location.search);
		var view = /[?&]view=([^&]*)/.exec(location.search);
		if (guid) mydeco_wl_url = mydeco_wl_url.replace('/search/', '/product/' + guid[1] + '/');
		if (top10) mydeco_wl_url = mydeco_wl_url.replace('/search/', '/top10' + top10[1]);
		mydeco_wl.ifr_attr.src = mydeco_wl_url + (query ? (mydeco_wl_url.substr(-6)=='query=' ? query[1] : '&query='+query[1]) : '') + (view ? '&view='+view[1] : '') +
			'&mydeco_resize=true&mydeco_parent_url=' + encodeURIComponent(location.href.replace(mydeco_wl.ifr_mess_reg, ''));
		mydeco_wl.ifr.frameBorder = 0; // must be set before appending (IE7).
		document.getElementById('mydeco_wrapper').appendChild(mydeco_wl.ifr);
		if(mydeco_wl.listner()){
			delete mydeco_wl.ifr_attr.src;
			delete mydeco_wl.ifr_style.height;
		}
		mydeco_wl.extend(mydeco_wl.ifr, mydeco_wl.ifr_attr);
		mydeco_wl.extend(mydeco_wl.ifr.style, mydeco_wl.ifr_style);
		location.hash = mydeco_wl.hash = '#';
		setInterval('mydeco_wl.listner()', 500);
	},
	
	listner: function(){
		try{
			if(mydeco_wl.hash == location.hash) {return false;}
			mydeco_wl.hash = location.hash;
			mydeco_wl.mess = (mydeco_wl.ifr_mess_reg.exec(location.hash)||[])[1];
			if(!mydeco_wl.mess) return false;
			mydeco_wl.mess = eval('('+unescape(mydeco_wl.mess)+')');
			location.hash = '#';
			if (mydeco_wl.ifr.src != mydeco_wl.mess.src) mydeco_wl.ifr.src = mydeco_wl.mess.src;
			mydeco_wl.ifr.style.height = mydeco_wl.mess.height;
			window.scrollTo(0,0);
			return true;
		}catch(e){}
	}
}
mydeco_wl.init();
