/**
 * Porovnani produktu
 */

//noconflict kvuli mootools
//jQuery.noConflict();
jQuery(document).ready(function() {
	// pridani/odebrani do porovavanych
	jQuery('#porovnat-detail a').click(function() {
		var o = jQuery(this);
		var href = jQuery(this).attr('href');
		jQuery.getJSON(href+'&ajax=1',function(data) {
			//alert(data['count']);
			var offset = jQuery('html').scrollTop();
			if(offset > 200) {
				jQuery('html').scrollTop(150);
			}
			jQuery('#compare .count').text(data['count']);
			jQuery('#compare').removeClass('hidden');
			function msgHide() {
				jQuery(".compareTooltip").slideUp("slow");
				clearInterval(msgInterval);
			}
			msgInterval = setInterval(msgHide,3000);
			var msg = '';
			if(data['name']) {				
				msg = '<div class="compareTooltip"><div class="top"></div><div class="body">Hodinky '+data['name']+' byly přidány do porovnání.</div><div class="bottom"></div></div>';
			} else {
				msg = '<div class="compareTooltip err"><div class="top"></div><div class="body">Tyto hodinky již máte v porovnání.</div><div class="bottom"></div></div>';
			}
			jQuery("#menu").after(msg);
		});
		return false;
	});
	jQuery('a.compareRemove').click(function() {
		var col = jQuery(this).parents('td').attr('class');

		var href = jQuery(this).attr('href');
		jQuery.get(href+'&ajax=1',function(data) {
			jQuery('#compare .count').text(data);
			jQuery('.porovnani .tl .count').text(data);
			if(data == 0) {
				jQuery('#compare').addClass('hidden');
				jQuery('.vypis').fadeOut();
				jQuery('.menu').after('<p class="static clear">Nebyly vybrány žádné produkty k porovnání.</p>');
			} else {
				jQuery('.'+col).fadeOut(function() {					
					//jQuery('.'+col).empty(function() {});
					jQuery('.'+col).empty();
				});
				

			}
			if(data <= 3) {
				//jQuery('#scrollLeft,#scrollRight').css('opacity',0.5);
                jQuery('#scrollLeft').click();
                jQuery('#scrollLeft,#scrollRight').hide();
			}
			size = data;
			
			
		});

		var doplneni = false;
		jQuery('#attr-doplneni .wrapper').each(function(i,e) {
			if(jQuery(this).text().length > 1) {
				
				var thisCol = jQuery(this).parents('td').attr('class');
				if(thisCol != col) {
					doplneni = true;
				}
			}
		});
		if(!doplneni) {
			jQuery('.doplneni-header').hide();
		}

		//jQuery.each(jQuery('#attr-doplneni .wrapper'),function(i,item) {
		

		return false;
	});

	jQuery('a.compareRemoveDesign').click(function() {
		var o = jQuery(this);
		var href = jQuery(this).attr('href');
		jQuery.get(href+'&ajax=1',function(data) {
			jQuery('#compare .count').text(data);
			jQuery('.porovnani .tl .count').text(data);
			if(data == 0) {
				jQuery('#compare').addClass('hidden');
				jQuery('.vypis').fadeOut();
				jQuery('.menu').after('<p class="static clear">Nebyly vybrány žádné produkty k porovnání.</p>');
			} else {
				jQuery(o).parent('div.product').fadeOut();
			}
		});
		return false;
	});

	/* reset */
	jQuery('a.reset').click(function() {
		if(!confirm('Opravdu chcete odebrat všechny hodinky z porovnání?')) {
			return false;
		}

		jQuery.get(jQuery(this).attr('href'),function(data) {
			jQuery('#compare').addClass('hidden');
			jQuery('.vypis').fadeOut();
		});
		return false;
	});


	/* Stranka s porovnanim */
	var col = 1;
	var size = jQuery('.images img').size();
	jQuery('#scrollLeft').css('opacity',0.5);
	if(size <=3) {
		jQuery('#scrollRight').css('opacity',0.5);
	}

	jQuery('#scrollRight').click(function() {
		if(col+3 <= size) {
			//jQuery('.col-'+col).slideLeft();
			//jQuery('.col-'+col).animate({width:'hide'},0);
			jQuery('.col-'+col).hide();
			//jQuery('.col-'+col).hide('slide',{direction:'left'},1000);
			//alert('1>'+col);
			/*origCol = col;
			jQuery('.col-'+col+'').not('.last .wrapper').hide('slide',{direction:'left'},1000);
			jQuery('.last .col-'+col+' .wrapper').hide('slide',{direction:'left'},1000,function() {
				jQuery('.col-'+origCol).hide();
			});*/
			col = col + 1;
			jQuery('#scrollLeft').css('opacity',1);
			
		}

		//dojel jsem na konec
		if(col+2 == size) {
			jQuery(this).css('opacity',0.5);
		}
		
		//alert(col);
		return false;
	});

	jQuery('#scrollLeft').click(function() {
		col = col - 1;
		if(col < 1) {
			col = 1;
		}
		//dojel jsem na zacatek
		if(col == 1) {
			jQuery(this).css('opacity',0.5);
		}


		jQuery('#scrollRight').css('opacity',1);
		//alert(col);
		//jQuery('.col-'+col).slideRight();
		//jQuery('.col-'+col).animate({width:'show'},0);
		jQuery('.col-'+col).show();
		return false;
	});

    /*jQuery('.tooltip').tooltip({
		extraClass: "pretty fancy hodinky",
		showBody: " | ",
		showURL: false,
		track: true,
		delay: 0

	});*/

	
})
