$(function(){
	$('#search').click(function(){
		$(this).val('');
	});
})


if($.browser.msie){
	userAgent = $.browser.version;
	userAgent = userAgent.substring(0,userAgent.indexOf('.'));	
	if (userAgent<7) DD_belatedPNG.fix('div,ul,img,button,a,input,li');
}

var current = new Array();

$(document).ready(function(){

	$("div#a a[class^='js-target-blank']").attr("target", "_blank");
	
	$("a.imageGallery").colorbox({
        'transition'        :    'elastic',
        'width'            :    "98%",
        'height'        :    '98%',
        'speed'            :    300,
	'maxWidth'	: "980px",
        'opacity'        :    0.75,
        'next'            :    "další",
        'previous'        :    "předchozí",
        'close'            :    "zavřít"
    });
	
	$("a#testfade").click(function(){
	    var oldImage = $("#featureImg").image();

	    $("#featureImgContainer").css({backgroundImage: "url('" + oldImage + "')"}); // TODO Escape URL

	    $("#featureImg").image(newImage).opacity(0).fadeIn();
	});
	
	$(".couchImages").each(function(){
		current.push($(this));
		});
	for (i = 0; i<current.length;i++){
		setTimeout("swapImage(" + i  + ",1)", (Math.random() * 500) + i*200  + 1100);
	}


});

function swapImage(id,firstrandom){

	$item = $("#ci_" + id + " img:first-child");
	while($item.length > 0){
		if($item.css("display")!="none"){
			$item.hide();
			if($item.next("img").length > 0) $item.next("img").show();
			else $item = $("#ci_" + id + " img:first-child").show();
			break;
		}
		$item = $item.next("img");

	}
	if ( firstrandom ){
		setInterval("swapImage(" + id  + ",0)",1000);
	}

}

