/*
* Siete library
* @Author: Alexander Gavazov
* @Site: www.studio.bg
*/


function writeSwf(element, swfFile, width, height, bgColor, parameters, flashId)
{
	var htmlCode = '';
	var flashVars = '';
	var embedColorCode = (bgColor) ? 'bgcolor="' + bgColor + '"' : 'wmode="transparent"';


	if(parameters)
	{
		for(var i in parameters)
		{
			if(typeof parameters[i] != 'string')
			{
				alert('Parameter: ' + i + ' must by string');
			}
			else
			{
				parameters[i] = parameters[i].replace(/&amp;/gi, '%26');
				parameters[i] = parameters[i].replace(/&/gi, '%26');

				flashVars += i + '=' + parameters[i] + '&';
			}
		}

		if(flashVars)
		{
			flashVars = flashVars.substr(0, flashVars.length - 1);
		}
	}

	htmlCode += '<object ' + (flashId ? 'id="' + flashId + '"' : '') + ' classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '">';
		htmlCode += '<param name="movie" value="' + swfFile + '" />';
		htmlCode += '<param name="quality" value="high" />';
		htmlCode += '<param name="flashvars" value="' + flashVars + '" />';
		htmlCode += '<param name="AllowScriptAccess" value="always" />';

		if(bgColor)
		{
			htmlCode += '<param name="bgcolor" value="' + bgColor + '" />';
		}
		else
		{
			htmlCode += '<param name="wmode" value="transparent" />';
		}

		htmlCode += '<embed ' + (flashId ? 'name="' + flashId + '"' : '') + embedColorCode + ' allowscriptaccess="someDomain" flashvars="' + flashVars + '" src="' + swfFile + '" quality="high" width="' + width + '" height="' + height + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	htmlCode += '</object>';

	element.innerHTML = htmlCode;
}


function emailReplace(emails, replaceStr)
{
	emails.each(function(node) {
		var mail = node.innerHTML.replace(replaceStr, '@');
		node.update('<a href="mailto:' + mail + '">' + mail + '</a>');
	});
}



function img_win(link_id)
{
	window.open(link_id.href, '_blank', 'status = 1, width = 250, height = 350, resizable = 0');
	return false;
}



function moveScroll(start, end)
{
	if(!this.Eingine)
	{
		this.Eingine = new VE;
	}

	this.Eingine.stop();
	this.Eingine.init(start, end, Easing.expoOut, 1);
	this.Eingine.onChange = function(position)
	{
		window.scrollTo(0, position)
	}
	this.Eingine.start();
}


document.observe('dom:loaded', function() {
	new Search({
		field: $$('#search input[type="text"]')[0],
		resultsContainer: $('search-results')
	});

	$('search').onsubmit = function() {
		document.location = $('search').action + '?q=' + $$('#search input[type="text"]')[0].value;
		return false;
	}

	$$('.sidebar-box ul.products-categories > li > ul > li > a').each(function(node) {
		node.onmouseover = function() { this.style.textDecoration = 'underline'; }
		node.onmouseout = function() { this.style.textDecoration = 'none'; }
	});

	if($$('input[class*=button]') && Prototype.Browser.Gecko)
	{
		$$('input[class*=button]').each(function(node) {
			node.style.paddingBottom = '4px';
		});
	}
});


Event.observe(window, 'load', function() {
	new BrandsSlider({
		prev: $$('#brands_slider .go_prev')[0],
		next: $$('#brands_slider .go_next')[0],
		container: $$('#brands_slider .container')[0],
		content: $$('#brands_slider .content')[0],
		elements: $$('#brands_slider .content li'),
		overs: $$('#brands_slider .content li img.over'),
		elementOffset: 46,
		stepOffset: 0
	});

	if($$('a[href="#ORDER"]')[0])
	{
		new Order({
			link: $$('a[href="#ORDER"]')[0],
			box: $('order_box'),
			image: $('product_image')
		});
	}
});