//hover box
(function($){
    $.fn.followBox = function(options) {
        options = $.extend({
            min : -20
        }, options);
 
        return this.each(function() {
            var $box = $(this);
            var boxHide = 1;
            var posRight = $box.css('right');
            var posLeft =  options.min ;
 
            var hideBox = function() {
                $box.not(':animated').animate({
                    'right': posRight
                },500, function() {
                    boxHide = 1;
                    $(document).unbind('mousedown', checkOuterBox);
 
                });
            }
 
            var checkOuterBox = function(event) {
                if ($(event.target).closest('.hover_box').length!=1) {
                    hideBox();
                }
            }
 
            $box.find('.facebook').bind('click', function() {
                if (boxHide!=1) return false;
                $box.not(':animated').animate({
                    'right' : posLeft
                },500, function() {
                    boxHide = -boxHide
                    $(document).bind('mousedown', checkOuterBox);
                });
				return false;
            });
        });
    }
})(jQuery);

(function($){
    $.fn.followBoxLottery = function(options) {
        options = $.extend({
            min : -20
        }, options);
 
        return this.each(function() {
            var $box = $(this);
            var boxHide = 1;
            var posRight = $box.css('right');
            var posLeft =  options.min ;
 
            var hideBox = function() {
                $box.not(':animated').animate({
                    'right': posRight
                },500, function() {
                    boxHide = 1;
                    $(document).unbind('mousedown', checkOuterBox);
					$box.css({'cursor':'pointer'});
                });
            }
 
            var checkOuterBox = function(event) {
                if ($(event.target).closest('.loterry_box').length!=1) {
                    hideBox();
                }
            }
 
			$box.bind('click', function() {				
				if (boxHide!=1) return;
				$box.not(':animated').animate({
					'right':posLeft
				},500, function() {
					boxHide = -boxHide
					$box.css({'cursor':'default'});
					$(document).bind('mousedown', checkOuterBox);
				});
			});		
        });
    }
})(jQuery);

(function($){
$(document).ready(function() {
//		var ie6=(parseInt($.browser.msie&&parseInt($.browser.version)==6&&window["XMLHttpRequest"]?"7.0":$.browser.version)==6)?true:false;
//		if (ie6) {DD_belatedPNG.fix('*');}

	$('#hover_box').followBox();
	$('#loterry_box').followBoxLottery({min:0});
	
	$('#loterry_box .see_more').click(function() {			
		$('body:eq(0)').append('<div class="popup_lottery"><div class="bg" style="width:'+$('body').width()+'px; height:'+$('body').height()+'px"></div><div class="content"><img src="/images/pl/plakat.jpg" /></div><span class="close"></span></div>');
		
        $('.popup_lottery .content img').load(function () {
			if ($(window).height()<=700) {			
				$(this).attr('height', $(window).height() - 60);
				var w = this.width;
				var h = this.height;
				$('.popup_lottery .content').css({
					'width': w,
					'height': h,
					'margin-left' : -(w/2)
				});				
				$('.popup_lottery .close').css('margin-left', w/2);
			}			
        });
		
		
		$('.popup_lottery .close').click(function() {
			$(this).parent().remove();
		});
		return false;
	});

//-----------------------------------------------------
//inputs placeholder
//-----------------------------------------------------
		if (!Modernizr.input.placeholder) {
			$('[placeholder]').focus(function() {
				var input = $(this);
				if (input.val() == input.attr('placeholder')) {
				input.val('');
				input.removeClass('placeholder');
			}
			}).blur(function() {
				var input = $(this);
				if (input.val() == '' || input.val() == input.attr('placeholder')) {
				input.addClass('placeholder');
				input.val(input.attr('placeholder'));
			}
			}).blur();
        //send form
			$('[placeholder]').parents('form').submit(function() {
				$(this).find('[placeholder]').each(function() {
					var input = $(this);
					if (input.val() == input.attr('placeholder')) {
						input.val('');
					}
				})
			});
		}



//-----------------------------------------------------
//header language select
//-----------------------------------------------------
        $('.language_select div').bind({
            'mouseenter':function() {
                $(this).find('ul').stop().css('opacity',0).show().animate({'opacity':0.9},300)
            },
            'mouseleave':function(e) {
                $(this).find('ul').stop().animate({'opacity':0}, 300, function() {$(this).hide();})
            }
        });



//-----------------------------------------------------
//navigation submenu
//-----------------------------------------------------
            $('.page_navigation').removeClass('page_navigation_css').find('li').bind({
                'mouseenter': function() {
                    $(this).find('ul').stop().css({'opacity':0,'z-index':100000}).show().animate({'opacity':1},300)
                },
                'mouseleave': function() {
                    $(this).find('ul').stop().animate({'opacity':0,'z-index':100000}, 300, function() {$(this).hide();})
                }
            });




//-----------------------------------------------------
//definition / question list
//-----------------------------------------------------
        if ($('.expand_list').length) {
            $('.expand_list dt').click(function() {
                var $dl = $(this).next('dl');
                if (!$dl.is(':animated')) {
                        $dl.slideToggle();
                }
            });
        }



//-----------------------------------------------------
//charge amount form
//-----------------------------------------------------
        $('#charge_amount_select').change(function() {
            if ($(this).find('option:selected').val()=='-1') {
                $('#other_amount').slideDown(200);
                $("#charge_amount").val("");
            } else {
                $('#other_amount').slideUp(200);
                $("#charge_amount").val($("#charge_amount_select option:selected").val());
            }
        });
        if ($('#charge_amount_select').find('option:selected').val()=='-1') {
            $('#other_amount').show();
        } else {
            $('#other_amount').hide();
            $("#charge_amount").val($("#charge_amount_select option:selected").val());
        }



//-----------------------------------------------------
//index page
//-----------------------------------------------------
    //top slider
    if (('.page_index').length) {
        var effect = ($.browser.msie)?'slide':'fade';
        $('#page_index_slider').slides({
            effect : effect,
            play: 4000,
            pause: 1500,
            hoverPause: true,
            pagination: true
        });

        $('#page_index_partners_slider').slides({
            effect : 'fade',
            play: 3000,
            pause: 1500,
            hoverPause: true,
            pagination: false,
            generateNextPrev: false
        })
    }



});
})(window.jQuery);

