$(document).ready(function(){
   
   
    bindImages('Pattern');
	
	bindImages('Border');
	
	
	$('#collectionToppingContainer img').click(function () {

		var id = $(this).attr('id').replace("collectionHeaderToggle_",'');
		
		$('#mediumRaumbild').attr('src',infoObjArray['raumbild_' + id]['medium']);
		
		$('#bigRaumbild').attr('src',infoObjArray['raumbild_' + id]['big']);
		
		$('#collectionToppingContainer .active').removeClass("active");
        
        $(this).addClass("active");    
	});
});

function bindImages(type){
	$('#collection' + type + 'Container img').click(function () {

       // var parentId = $(this).parent().parent().attr('id');
        
		//var img = $('img.collectionHeader', $(this).parent().parent().parent());
        
		
		
        //var id = $(this).attr('id').replace(/Toggle/ig,"Header");
		
		updateDetailInfo(this.id.replace('collection' + type + 'Toggle_',''),type);

		
        //var dst = $("#"+id).attr('src');

        //img.attr('src', dst);
		
		$('#collection' + type + 'Container .active').removeClass("active");
        
		/**
        $("#"+parentId+" .collectionGrid img").each(function () {
            $(this).removeClass("active");
        });
       
        $("#"+parentId+" .collectionDetail").each(function () {
            //$(this).addClass("hidden");
        });
        */
        
        $(this).addClass("active");
        
		//var id = $(this).attr('id').replace(/Toggle/ig,"Detail");
        //$("#"+id).removeClass("hidden");

		//document.getElementById('zoom').className=id+'popup';
		
		
    });
}

function updateDetailInfo(uid,type){
	infoObj = infoObjArray[uid];
	for(key in infoObj){
		if(typeof infoObj[key]!= 'function' && $('#' + key + 'Value')){
			value = infoObj[key];
			$('#' + key + 'Value' + type).html(value);
		}
	}
	$('#bigProductImage' + type).attr('src','uploads/tx_w4produktfinder/' + infoObj.image_detail);
	//console.log(infoObj);
}
