$(document).ready(function() {
	zindex = 500;
	$('ul#main-menu > li').each(function(index, element) {
		$(element).css('zIndex', zindex);
		zindex -= 10;
	});	
	
	if ($('a#date-sort')) {
		$('a#date-sort').click(function() {
			if ($(this).attr('class') == 'asc') {
				$('input#news-sort-select').val('desc');
			} else {
				$('input#news-sort-select').val('asc');
			}
			$('form#news-filter').submit();
		});
	}
	
	if ($('select#news-category-select')) {
		$('select#news-category-select').change(function() {
			$('form#news-filter').submit();		
		});
	}
	
	if ($('select#news-author-select')) {
		$('select#news-author-select').change(function() {
			$('form#news-filter').submit();		
		});
	}
	
	if ($('div.cms-content')) {
		$('div.cms-content img').jcaption({
			imageAttr: 'title',
			wrapperClass: 'image-caption',
			requireText: true,
			removeStyle: false,
			copyStyle: true,
			ignoreStyle: ['height'],
			autoWidth: false
		});
	}
	
	if($('div.slideshow') && $('ul.slideshow-pagination')) {
		$('ul.slideshow-pagination').tabs('div.slideshow-container > div.slideshow', {
			//effect: 'fade',
			//fadeInSpeed: 2000,
  			//fadeOutSpeed: 2000,
  			tabs: 'a.tab',
			rotate: true
		}).slideshow({
			autoplay: true,
			interval: 7000 // 7 sec
		});
	}
	
	if($('div.slideshow-vertical')) {
		$('div.slideshow-vertical').jCarouselLite({
			auto: 8000,
			speed: 1000,
			vertical: true,
			visible: 1
		});
	}
	
	if ($('div.poll_result ul li')) {
		$('div.poll_result ul li').each(function(index, value) {
			percent = $(value).find('div.percent').text();
			percent = percent.replace(/(.*)%$/, '$1');
			bar_width = parseInt(220 / 100) * percent;
			$(value).find('div.bar').animate({width: bar_width}, 500); //css('width', bar_width);
		})
	}
	
	if ($('a.footer_sponsor')) {
		$('a.footer_sponsor').mouseover(function() {
			new_img_src = $(this).attr('rel');
			old_img_src = $(this).children('img').attr('src');
			
			$(this).children('img').attr('src', new_img_src);
			$(this).attr('rel', old_img_src);
		}).mouseout(function() {
			new_img_src = $(this).attr('rel');
			old_img_src = $(this).children('img').attr('src');
			
			$(this).children('img').attr('src', new_img_src);
			$(this).attr('rel', old_img_src);
		})
	}
	
	if ($('a.zoom_button')) {
		$('a.zoom_button').lightBox({fixedNavigation:true});
	}
	
	if ($('div#sponsor_cycle')) {
		$('div#sponsor_cycle').cycle({
			fx: 'fade',
			speed: 2000,
			timeout: 8000
		});
	}

    if ($('input#search_input')) {
        $('input#search_input').focus(function() {
            var $value = $(this).val();
            if ($value != '' && $value == 'Suchbegriff...') {
                $(this).val('');
                $(this).css('font-style', 'normal');
                $(this).css('color', '#000000');
            }
        }).blur(function() {
            var $value = $(this).val();
            if ($.trim($value) == '') {
                $(this).val('Suchbegriff...');
                $(this).css('font-style', 'italic');
                $(this).css('color', '#656565');
            }
        });
    }

    if ($('a#link_chess_national img')) {
        $('a#link_chess_national img').hover(function() {
            var $img_src = $(this).attr('src');
            var $new_img_src = $img_src.replace(/(.*)\.png/g, '$1_hoover.png');
            $(this).attr('src', $new_img_src);
        }, function() {
            var $img_src = $(this).attr('src');
            var $new_img_src = $img_src.replace(/(.*)_hoover\.png/g, '$1.png');
            $(this).attr('src', $new_img_src);
        });
    }

    if ($('a#link_chess_international img')) {
        $('a#link_chess_international img').hover(function() {
            var $img_src = $(this).attr('src');
            var $new_img_src = $img_src.replace(/(.*)\.png/g, '$1_hoover.png');
            $(this).attr('src', $new_img_src);
        }, function() {
            var $img_src = $(this).attr('src');
            var $new_img_src = $img_src.replace(/(.*)_hoover\.png/g, '$1.png');
            $(this).attr('src', $new_img_src);
        });
    }
});
