$(document).ready(function()
{
	FLIR.replace($('#box_categories .level_0 li a')[0]);

	/*
	$('#breadcrumb').each( function() {
		FLIR.replace(this, new FLIRStyle({ cFont:'helvetica_heavy'}));
	});
	*/

	$('.aachen').each( function() {
		FLIR.replace(this);
	});

	$('.hheavy').each( function() {
		FLIR.replace(this, new FLIRStyle({ cFont:'helvetica_heavy'}));
	});

	$('#also_purchased h2.flir2').each( function() {
		FLIR.replace(this, new FLIRStyle({ cFont:'helvetica_heavy'}));
	});

	$('.flir').each( function() {
		FLIR.replace(this, new FLIRStyle({ realFontHeight: 'true' }));
	});

	if ( typeof endtime != 'undefined' ) {
		$('#ls_countdown_content').countdown({until: +endtime, compact: true, format: 'HMS'});
	}

	$('#product_info').show();
});

function print_product(prd_id)
{
	window.open('print_product_info.php?products_id=' + prd_id, 'popup', 'toolbar=0, width=640, height=600');
}

/**
 * select_option
 *
 */
function select_option(option_id, value_id)
{
	$('.option_' + option_id).each( function() {
		if ( this.value == value_id ) {
			this.checked = 'checked';
		} else {
			this.checked = '';
		}
	});

	//option_{$option.ID}_{$item.ID}
	$('#option_' + option_id + ' img').removeClass();
	$('#option_' + option_id + '_' + value_id).addClass('active');
}

function set_word(color)
{
	if ( color == '' ) {
		return false;
	}

	var src = $('#pic img')[0].src;
	var href = $('#pic a')[0].href;

	src = src.replace(/\/[A-F0-9]{6}\//, '/' + color + '/');
	href = href.replace(/\/[A-F0-9]{6}\//, '/' + color + '/');
	$('#pic img')[0].src = src;
	$('#pic a')[0].href = href;
}


function set_pic(pic, ext)
{
        if ( pic == '' || ext == '' ) {
                return false;
        }

        pic = '/' + pic + '.' + ext;
	if(typeof($('#pic img')[0])=="undefined")
	{
        var src = $('#picb img')[0].src;
        var href = $('#picb a')[0].href;

        src = src.replace(/\/[^\/]*\.\w{3}$/, pic);
        src = src.replace(/info_images/, 'preview2/info');

        href = href.replace(/\/[^\/]*\.\w{3}$/, pic);
        href = href.replace(/popup_images/, 'preview2/popup');

        $('#picb img')[0].src = src;
        $('#picb a')[0].href = href;
	}
	else
	{
        var src = $('#pic img')[0].src;
        var href = $('#pic a')[0].href;

        src = src.replace(/\/[^\/]*\.\w{3}$/, pic);
        src = src.replace(/info_images/, 'preview2/info');

        href = href.replace(/\/[^\/]*\.\w{3}$/, pic);
        href = href.replace(/popup_images/, 'preview2/popup');

        $('#pic img')[0].src = src;
        $('#pic a')[0].href = href;
	}
}

function set_price(price)
{
	if ( price.search(/\./) == -1 ) {
		price += ',00';
	} else {
		price = price.replace(/\./, ',');
	}

	var temp = price.split(',');
	if ( temp[1].length == 1) {
		price += '0';
	}

	price += ' €';
	if(typeof($('#picb img')[0])!="undefined")
	{
		price += ' - 20% Rabatt bereits berücksichtigt'
	}
	$('#products_price').text(price);
}

/**
 * select_color
 *
 */
function select_color(option, id)
{
	select_option(option, id);

}

function tell_a_friend_submit()
{
	$.post('ajax.php?action=tell_a_friend&submit=1&height=500&width=800',
		$('#tell_a_friend form').serialize(),
		function(data){
			$('#TB_ajaxContent').html(data);
		}
	);
}

function chars_left(max)
{
	var l = $('#text').val().length;
	l = max - l <= 0 ? 0 : max - l;
	var raw = $('#chars_left_raw').text().replace(/%u/, l);
	$('#chars_left').text(raw)
}

/**
 * trim
 *
 */
function trim(s)
{
	if ( typeof s != 'undefined' ) {
		s = s.replace (/\s+$/, '');
	} else {
		s = '';
	}
	return s;
}

function toggle_info_box(me)
{
	$('.shipping_info_box').hide();

	if ( typeof me != 'undefined' ) {
		$('#' + me).show();
	}
}


