/**
 * JavaScrits
 */

$(document).ready(function()
{
    showErrorMessage('');
    
    $('.deco_dropdown').selectbox();
});
//---------------------------------------------------------------

/*
	Strips spaces from start and end of string
	Param:
		str string (text)
*/
function trimString (str)
{
	while (str.charAt(0) == ' ')
		str = str.substring(1);
	while (str.charAt(str.length - 1) == ' ')
		str = str.substring(0, str.length - 1);

	return str;
}
//---------------------------------------------------------------

function showErrorMessage(text)
{
    if (text)
    {
        $('#error-message').html(text);
        $('#error-message-container a').trigger('click');
    }
    else
    {
        var html = '';
        
        var errMsgContainer = $('.page-messages-container');
        if (errMsgContainer.length)
        {
            if (errMsgContainer.length > 1)
            {
                errMsgContainer.each(function(){
                    html += $.trim($(this).html());
                });
            }
            else
            {
                html = $.trim(errMsgContainer.html());
            }
        }
        
        if(html)
        {
            $('#error-message').html(html);
            $('#error-message-container a').trigger('click');
        }
    }

}
//----------------------------------------------------------

var iCurrentlyOpenId = -1;
var bCurrentlyOpenTip = false;
var contentOffsetTop = false;

function carousel_tip_action( obj, action, wich, product_link ){
	jQuery('#tip_target_url').attr('href',product_link);	
    
	if( wich == 'src' ){
		if( action == 'show' ){
			var lrel = jQuery(obj).attr('rel');
			
            if (!jQuery('#extra_' + lrel).length)
            {
                return;
            }
            
            if(contentOffsetTop === false)
            {
                var contentOffset = jQuery('#content').offset();
                contentOffsetTop = contentOffset.top;
            }
            
			var map_pos = jQuery('#products_carousel').offset();
			var image_pos = parseInt(jQuery('#products_carousel').css('left'));
			var map_tip_pos = jQuery(obj).offset();
            
			jQuery('#carousel_tip').show().css({ 'top': (map_tip_pos.top - contentOffsetTop - 10) + 'px', 'left': (map_tip_pos.left - map_pos.left + 56 + image_pos) + 'px' });
			jQuery('#carousel_tip .title_show').html(jQuery('#extra_' + lrel + ' .title').html());
			jQuery('#carousel_tip .price').html(jQuery('#extra_' + lrel + ' .price_data').html());
			jQuery('#carousel_tip .arrow').show();
			iCurrentlyOpenId = 1;
			bCurrentlyOpenTip = false;
		} else {
			iCurrentlyOpenId = -1;
			bCurrentlyOpenTip = false;
			var t = setTimeout("carousel_tip_action_hide( )", 250 );
		}
	} else {
		if( action == 'show' ){
			bCurrentlyOpenTip = true;
			iCurrentlyOpenId = -1;
		} else {
			bCurrentlyOpenTip = false;
			iCurrentlyOpenId = -1;
			var t = setTimeout("carousel_tip_action_hide( )", 250 );
		}
	}
	
}
//----------------------------------------------------------

function carousel_tip_action_hide( ){
	if( bCurrentlyOpenTip == false && iCurrentlyOpenId == -1 ){
		jQuery('#carousel_tip .title_show').html('');
		jQuery('#carousel_tip .price').html('');
		jQuery('#carousel_tip').hide();
		iCurrentlyOpen = -1;
	}
}
//----------------------------------------------------------

