/**
    Inetshop © 2001 www.inetshop.cz / Inetgroup, s.r.o. © 2011 www.inetgroup.cz
    v1 111122
**/
$(document).ready(function()
{
    imagePreview();
    
    /** Anketa **/
    $('.pollclick').click(function()
    {
        var voteid = $(this).attr( 'rel' );
        $.ajax({
            url: '/ajax/poll.php',
            data: ({voted: voteid}),
            dataType: 'html',
            type: 'POST',
            success: function( ret ){
                if( ret ) {
                    $('#poll').html( ret )
                } else {
                    $('#pollError').show();
                    $('#pollError').html( 'Pravděpodobně jste již halsoval(a)' )
                }
            }
        });

        return false;
    });
    
    /** Nahled obrazku **/
    $('.thumbnail').fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true
	});
    
    /** Popup **/
    $('.popup').click(function(e){
        window.open($(this).attr('href'), $(this).attr('title'), '450', '330');
        e.preventDefault();
        
        return false;
    });
    
    $('.iframe').fancybox({
		'width'				: 500,
		'height'			: 210,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
});
this.imagePreview = function()
{
	xOffset = 10;
	yOffset = 20;
	$('.preview').hover(function(e){
		this.t = this.title;
		this.title = '';
		var c = (this.t != '') ? '<br />' + this.t : '';
		$('body').append( '<div id="imagePreview"><img src="/images/catalog/f/' + this.alt + '" width="250" />' + c + '</div>' );
		$('#imagePreview')
			.css('top',(e.pageY - xOffset) + 'px')
			.css('left',(e.pageX + yOffset) + 'px')
			.fadeIn('fast');
    },
	function(){
		this.title = this.t;
		$('#imagePreview').remove();
    });
	$('.preview').mousemove(function(e){
		$('#imagePreview')
			.css('top',(e.pageY - xOffset) + 'px')
			.css('left',(e.pageX + yOffset) + 'px');
	});
};
this.transDop = function(id, type)
{
    if( type == 'paymethod' ) {
        var ptypeval = $('#transport_price').attr('value')
    } else {
        var ptypeval = $('#paymethod_price').attr('value')
    }
    $.ajax({
        url: '/ajax/paymethods.php',
        data: ({id: id, type: type, price: $('#totalPriceDphH').attr('value') + '|' + ptypeval}),
        dataType: 'xml',
        type: 'POST',
        complete: function( ret )
        {
            var xml = ret.responseXML;            
            //$('#catch_' + type + '_text').html( xml.getElementsByTagName('title')[0].childNodes[0].nodeValue );
            $('#' + type + '_title').html( xml.getElementsByTagName('title')[0].childNodes[0].nodeValue );
            $('#' + type + '_price').attr( 'value', xml.getElementsByTagName('price')[0].childNodes[0].nodeValue );
            $('#totalPriceDph').attr( 'value', xml.getElementsByTagName('totaldphprice')[0].childNodes[0].nodeValue );
        }
    });
    
    return false;
};
this.transDopCheck = function( ids, type )
{
    var idarray = ids.split(',');
    if( type == 'tm' ) {
        var regexp = /chckt/
        var regexplbl = /lbl_chckt_/
    } else {
        var regexp = /chckp/
        var regexplbl = /lbl_chckp_/
    }
    
    $('#tbl_' + type + ' input').each(function(){
        if( in_array($(this).attr('id').replace(regexp, ''), idarray))
        {
            $(this).attr('disabled', false)
        } else
        {
            $(this).attr('disabled', true)
        }
    });
    $('#tbl_' + type + ' label').each(function(){
        if( in_array($(this).attr('id').replace(regexplbl, ''), idarray))
        {
            $(this).addClass('bold')
            $(this).removeClass('note')
        } else
        {
            $(this).addClass('note')
            $(this).removeClass('bold')
        }
    });
}
this.in_array = function(needle, haystack, strict) {
    var found = false, key, strict = !!strict;for(key in haystack){if((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)){found = true;break;}}return found;
}
this.headline_rotate = function() {
	current_headline = (old_headline + 1) % headline_count;
	$("div.headline:eq(" + old_headline + ")").animate({top: -20},"slow", function() {
      	$(this).css('top', '20px');
    });
  	$("div.headline:eq(" + current_headline + ")").animate({top: 5},"slow");  
  	old_headline = current_headline;
}
function fbs_click() {
    u=location.href;
    t=document.title;
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&amp;t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=1000,height=600');
    return false;
}
