﻿var isHomepage = false;

// Replace titles
Cufon.replace('.mainmenu a');
Cufon.replace('.latestnews h2');
Cufon.replace('.innercontent .subtitle');
Cufon.replace('.innercontent h1');
Cufon.replace('.quicklink h4');
Cufon.replace('.banner h2');

jQuery(function() {
	Cufon.now();
	
    // Left menu opening/closing
    jQuery('.leftmenu li').each(function() {
        var oListItem = $(this);
        if (oListItem.find('ul').length > 0) {
			if (!oListItem.is('.active'))
			{
				oListItem.find('ul').hide();
				oListItem.find('span > span').addClass('closed').click(function(event) {
					event.preventDefault();
					var oSign = jQuery(this);
					if (oSign.is('.open')) {
						jQuery(this).removeClass('open');
						jQuery(this).addClass('closed');
						jQuery(this).parent().next('ul').hide();
					}
					else {
						jQuery(this).removeClass('closed');
						jQuery(this).addClass('open');
						jQuery(this).parent().next('ul').show();
					}
				});
			}
			else
			{
				oListItem.find('span > span').addClass('open');
			}
        }
    });

    // Table column coloring
    jQuery('.text table tbody tr').each(function() {
        jQuery(this).children().each(function(iIndex) {
            if (iIndex % 2 == 1) {
                jQuery(this).addClass('even');
            }
        });
    });
    // TODO: remove bottom border on last row

    // External links
    jQuery('a.external').attr('target', '_blank');

    jQuery('.spot > a').colorbox();
	
	// Product detail image switching
	jQuery('.productdetail .thumbnail').click(function(event) {
		event.preventDefault();
		var oThumb = jQuery(this);
		oThumb.parent().prev().find('img').attr('src', oThumb.attr('href'));
		oThumb.parent().find('.thumbnail').removeClass('active');
		oThumb.addClass('active');
	});

    // Set flash background
    var flashVars = { fvDataXml: '/xml/backimages.xml' };
	flashVars.fvUseInitFade = isHomepage;
	
    var flashParams = { wmode: 'transparent', scale: 'noscale', quality: 'high', play: 'true', loop: 'true', bgcolor: '#1A0601', allowFullScreen: 'true', allowScriptAccess: 'sameDomain', salign: 'lt' };
    var flashAttributes = { align: 'left' };
    var bodyHeight = jQuery(document).height();
    swfobject.embedSWF('/swf/xmlFullscreenCross.swf', 'FlashBackground', '100%', bodyHeight, '9.0.0', '/swf/expressInstall.swf', flashVars, flashParams, flashAttributes);
});

function blurfocus(oInput, sBlurText, sFocusText)
{
	if (jQuery(oInput).val() == sBlurText)
	{
		jQuery(oInput).val(sFocusText)
	}
}
