
Event.observe(window, 'load', replaceHeadersWithFlash);
Event.observe(window, 'load', replaceCustomerServiceWithFlash);
Event.observe(window, 'load', replaceCartTitleWithFlash);

function replaceCustomerServiceWithFlash(e)
{

	var customerService = $('customerservice');
 		
		var flashvars = false;
		var fontSizeString = customerService.getStyle('font-size');
		var fontSizeNumber = parseInt(fontSizeString);
		
		var color = customerService.getStyle('color');
		
		if(color.indexOf('#')==-1)
		{
			color = rgb2hex(color)
		}
		
		var fontColor = color;		
		
		$$('.customer-service')[0].setStyle({marginRight:'-8px'});
		var params = {flashvars:"Title=" + urlencode(customerService.innerHTML) + "&Size=" + (fontSizeNumber+7)+ "&Color=" + fontColor, scale: "noscale", salign: "tl", wmode:"transparent"};
		var attributes = {};
		swfobject.embedSWF("http://195.74.38.160/skin/frontend/default/default/flash/header.swf?t=" +new Date().getTime(), customerService.id, customerService.offsetWidth+80, customerService.offsetHeight + 10 + parseInt(customerService.getStyle('padding-bottom')), "9.0.0", null, flashvars, params, attributes);

}

function replaceCartTitleWithFlash(e)
{

		var cartTitle = $$('.top-cart .cart-title h2');
 		
 		$$('.top-cart .amount')[0].setStyle({marginTop:'-2px'});
 		
 		cartTitle[0].id='top-cart-title';
 		
		var flashvars = false;
		var fontSizeString = cartTitle[0].getStyle('font-size');
		var fontSizeNumber = parseInt(fontSizeString);
		var color = cartTitle[0].getStyle('color');
		
		if(color.indexOf('#')==-1)
		{
			color = rgb2hex(color)
		}
		
		var fontColor = color;
		var params = {flashvars:"Title=" + urlencode(cartTitle[0].innerHTML) + "&Size=" + (fontSizeNumber+5)+ "&Color=" + fontColor, scale: "noscale", salign: "tl", wmode:"transparent"};
		var attributes = {};
		swfobject.embedSWF("http://195.74.38.160/skin/frontend/default/default/flash/header.swf?t=" +new Date().getTime(), 'top-cart-title', 200, cartTitle[0].offsetHeight + 5 + parseInt(cartTitle[0].getStyle('padding-bottom')), "9.0.0", null, flashvars, params, attributes);

}

function replaceHeadersWithFlash(e)
{

	var allH1Headers = $$('h1');
 
	for(i = 0; i < allH1Headers.length; i++)
	{
		allH1Headers[i].id='header1' + i
		
		var flashvars = false;
		var fontSizeString = allH1Headers[i].getStyle('font-size');
		var fontSizeNumber = parseInt(fontSizeString);
		
		var color = allH1Headers[i].getStyle('color');
		
		if(color.indexOf('#')==-1)
		{
			color = rgb2hex(color)
		}
		
		var fontColor = color;
		
		var params = {flashvars:"Title=" + urlencode(allH1Headers[i].innerHTML) + "&Size=" + (fontSizeNumber)+ "&Color=" + fontColor, scale: "noscale", salign: "tl", wmode:"transparent"};
		var attributes = {};
		swfobject.embedSWF("http://195.74.38.160/skin/frontend/default/default/flash/header.swf?t=" +new Date().getTime(), "header1" + i, allH1Headers[i].offsetWidth, allH1Headers[i].offsetHeight + parseInt(allH1Headers[i].getStyle('padding-bottom')), "9.0.0", null, flashvars, params, attributes);

	}
	
	var allH2Headers = $$('.postTitle h2');
 
	for(i = 0; i < allH2Headers.length; i++)
	{
		allH2Headers[i].id='header2' + i
		
		var flashvars = false;
		var fontSizeString = allH2Headers[i].getStyle('font-size');
		var fontSizeNumber = parseInt(fontSizeString);
		
		var color = allH2Headers[i].getStyle('color');
		
		if(color.indexOf('#')==-1)
		{
			color = rgb2hex(color)
		}
		
		var fontColor = color;
		
		var params = {flashvars:"Title=" + urlencode(allH2Headers[i].innerHTML) + "&Size=" + (fontSizeNumber)+ "&Color=" + fontColor, scale: "noscale", salign: "tl", wmode:"transparent"};
		var attributes = {};
		swfobject.embedSWF("http://195.74.38.160/skin/frontend/default/default/flash/header.swf?t=" +new Date().getTime(), "header2" + i, allH2Headers[i].offsetWidth, allH2Headers[i].offsetHeight, "9.0.0", null, flashvars, params, attributes);

	}
}

function urlencode(str)
{
	str = escape(str);
	str = str.replace('+', '%2B');
	str = str.replace('%20', '+');
	str = str.replace('*', '%2A');
	str = str.replace('/', '%2F');
	str = str.replace('@', '%40');
	return str;
}


function rgb2hex(str)
{
	var rgb = str.match(/\d+/g);              
    return "#" + parseInt(rgb[0]).toColorPart() + parseInt(rgb[1]).toColorPart() + parseInt(rgb[2]).toColorPart();
} 
 


/*-----------------------------------------------------------
    Toggles element's display value
    Input: any number of element id's
    Output: none 
    ---------------------------------------------------------*/
function toggleDisp() {
    for (var i=0;i<arguments.length;i++){
        var d = $(arguments[i]);
        if (d.style.display == 'none')
            d.style.display = 'block';
        else
            d.style.display = 'none';
    }
}

/*-----------------------------------------------------------
    Toggles tabs - Closes any open tabs, and then opens current tab
    Input:     1.The number of the current tab
                    2.The number of tabs
                    3.(optional)The number of the tab to leave open
                    4.(optional)Pass in true or false whether or not to animate the open/close of the tabs
    Output: none 
    ---------------------------------------------------------*/
function toggleTab(num,numelems,opennum,animate) {
	animate=false;
    if ($('tabContent'+num).style.display == 'none'){
        for (var i=1;i<=numelems;i++){
            if ((opennum == null) || (opennum != i)){
                var temph = 'tabHeader'+i;
                var h = $(temph);
                if (!h){
                    var h = $('tabHeaderActive');
                    h.id = temph;
                }
                var tempc = 'tabContent'+i;
                var c = $(tempc);
                if(c.style.display != 'none'){
                    if (animate || typeof animate == 'undefined')
                        Effect.toggle(tempc,'blind',{duration:0.5, queue:{scope:'menus', limit: 3}});
                    else
                        toggleDisp(tempc);
                }
            }
        }
        var h = $('tabHeader'+num);
        if (h)
            h.id = 'tabHeaderActive';
        h.blur();
        var c = $('tabContent'+num);
        c.style.marginTop = '2px';
        if (animate || typeof animate == 'undefined'){
            Effect.toggle('tabContent'+num,'blind',{duration:0.5, queue:{scope:'menus', position:'end', limit: 3}});
        }else{
            toggleDisp('tabContent'+num);
        }
    }
}
