$(document).ready(function(){


/**
 * Shadow
 */
	/*
var shadow_cfg = {
	left: -1,
	top: 2,
	opacity: 0.4,
	color: '#000',
	blur: 2
}
var images = $('#col1_content .img-full img, .img-left img, .img-right img');

$(images).addClass('shadow');
$(images).dropShadow(shadow_cfg); 	
*/


	
/**
 * Lighbox
 */	


var lightbox_config = {
 	maxWidth: '80%',
 	maxHeight: '80%',
	opacity: 0.8,
 	current: '{current} von {total}',
 	prevous: 'Voriges',
 	next: 'Nächstes',
 	close: 'Schließen'
 }


/**
 * Carousel
 */

var carousel_list = $('#mycarousel li');
//console.log(mycarousel_getItemHTML(carousel_list[0]));
 	
function carousel_in (carousel, item, i, state, evt)
{
// The index() method calculates the index from a
// given index who is out of the actual item range.
	var idx = carousel.index(i, carousel_list.length);
	test = carousel.add(i, carousel_html(carousel_list[idx - 1]));
	//console.log(carousel_list);
	//console.log(test);
	(test).find('a:first').colorbox(lightbox_config);
	//tb_init($(test).find('a:first'));
};

function  carousel_out (carousel, item, i, state, evt)
{
carousel.remove(i);
};

/**
* Item html creation helper.
*/
function carousel_html (item)
{
	
return $(item).html();
};

var carousel_cfg = {
	scroll: 4,
	wrap: 'circular',
    itemVisibleInCallback: {onBeforeAnimation: carousel_in},
    itemVisibleOutCallback: {onAfterAnimation: carousel_out}
    };

jQuery('#mycarousel').jcarousel(carousel_cfg);
 
/**
 * Produktkonfigurator
 */
/*
$('#products .location2').hide();
$('#products input').removeAttr('checked');
*/

var location1 = function  (e) {
	   $('#products .location2 input').removeAttr('checked');
   // console.log(this.attr('value'));
       //  console.log($(this).val());
   var classname = $(this).val();
   if (!classname) {
       	$('#products .location2 p').hide();
       	$('#products .location2').hide();
   }else {
       	$('#products .location2 p').hide();
       	$('#products .location2 .'+classname).show();
       	$('#products .location2').show();
   }
	
}

var location2 = function (e) {
		var cat = $(this).val();
	
	//var cat = $('#products .location2 input[checked=checked]').val();
	//console.log ($('#products #location2').val());
	//$('#products').submit();
	$("#ajax").html('<p class="loading"><img src="img/loading.gif" /> Loading …</p>');
	$("#ajax").load('modules/produktfinder.php?mode=products&cat='+cat+' #results',function(){
		//console.log(this);
		$(this).find('.item a').each(function (i) {

	dest = $(this).attr('href');
	dest = dest;
	//console.log(dest);
    $(this).colorbox({inline:true, href:dest});
    // $(this).colorbox({width: '50%', inline:true, href: "#details_01"});
});	
});
};


$("#products .location1 input").bind("click", location1);
$("#products .location2 input").bind("click",location2);
$("#products .location1 input:first").click().focus();

//$("#products .location2 input:first").click().focus();



var image_links = $('.jcarousel-item img, #col1_content img').parent('a[href$=.jpg], a[href$=.png], a[href$=.gif]');


$(image_links).colorbox(lightbox_config);
//$(image_links).addClass('thickbox');

$('#materials').find('a').each(function (i) {

	dest = $(this).attr('href');
	dest = dest;
	//console.log(dest);
    $(this).colorbox({inline:true, href:dest});
});	





});