﻿Cufon.replace('#head ul li a, .module h3',{fontFamily: 'Helvetica 55 Roman', hover: {color: '#009661'}});
Cufon.replace('.module h1, .module h2, .topline, .teaser, .trendblog_foot_archiv h4 span, .sidebar_tagcloud h4 span,.cluetip-product_detail_layer .price, .teaser_content h3, .teaser_content h2, .provision td, #sedcard h2, #sedcard ul, #sedcard label,#sedcard input,#sedcard dl,#sedcard strong,,#sedcard .data', {fontFamily: 'Helvetica 45 Light' }); 

function formTooltipHandling (){
	var formInputElm = $('.module form input[type=text]')
	var formTextareaElm = $('.module form textarea');
	var formSelectElm = $('.module form select');
	$('.module form .info_default').hide();
	formInputElm.focus(function() {
		$(this).parent().find('.info_default').fadeIn('fast');
		$(this).addClass('class name');
	});
	formInputElm.blur(function() {
		$(this).parent().find('.info_default').fadeOut('fast');
	});		
	formTextareaElm.focus(function() {
		$(this).parent().find('.info_default').fadeIn('fast');
	});
	formTextareaElm.blur(function() {
		$(this).parent().find('.info_default').fadeOut('fast');
	});	
	$('.select').hover(function() {
		$(this).find('.info_default').fadeIn('fast');
	}, function() {
		$(this).parent().find('.info_default').fadeOut('fast');
	});	

	$("input[type=text]").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
}

function formData(cluetip, cluetipInner) {
	$('form').jNice(); // REINITIALIZE FORM REPLACEMENT
	Cufon.refresh(); // REINITIALIZE FONT REPLACEMENT
	formTooltipHandling();
	//LOKAL
	layerOptions('#bubblecontent', 'tellafriend.php', '#myForm2');
	layerOptions('#bubblecontent', 'newsletter.php', '#myForm1');
	
	//SERVER
	layerOptions('#bubblecontent', 'nlpopup.frm', '#myForm3');
	layerOptions('#bubblecontent', 'tell_a_friend.frm', '#myForm4');
	
	// SET CAPTCHA REFRESH LINKS                                                                                                
	initCaptchaRefreshLinks();
	
}
                                                                                                                                                                                                                                                               
function initCaptchaRefreshLinks(){                                                                                                 
	$('#captchaLink').click(function () {                                                                                     
		$('#captchaImage').attr('src', '/DE/de/corp/captcha.jpg?' + Math.floor(Math.random()*100) );                                 
	});                                                                                                                   
}

function layerOptions (targetID, path, formID) {
	// 	 	url: path 
	var options = { 
		target: targetID, 
		success: showResponse,
	 	//cache: false,
	 	url: $(formID).attr("action") 
	}; 
	$(formID).submit(function() { 
		$(this).ajaxSubmit(options); 
		return false; 
	});
}

// post-submit callback 
function showResponse(responseText, statusText, xhr, $form)  { 
	formData();
}


function callTellafriend () {
	$("a.tellafriend").trigger("click");
}


// GALLERY MODULE
function gallery(data, galleryID) {	
	var $galleryOutput = $("#" + galleryID);
	var $galleryThumblistOpen = '<a class="prev">PREV</a><div class="thumbnails"><ul>';
	var $galleryThumblistClose = '</ul></div><a class="next">NEXT</a>';
	var $galleryThumbs = "";
	$.each(data, function (i, item) {
		$galleryThumbs += '<li pos="'+item.pos+'" title="'+ item.title +'" rel="'+ item.path_thick +'"><a href="" rel="'+ item.path_small +'"><img src="'+ item.path_thumb +'" alt="" width="52" height="28"/></a></li>';
	});

	$galleryOutput.append($galleryThumblistOpen + $galleryThumbs + $galleryThumblistClose);
	
	// CAROUSEL
	$("#"+ galleryID + " .thumbnails").jCarouselLite({
	    btnNext: "#" + galleryID + " .next",
	    btnPrev: "#" + galleryID + " .prev",
		visible: 4,
		scroll: 1,
		circular: false
					
	});
	
	var thumbnails = $("#" + galleryID + ' .thumbnails li');
	var elImg = $("#" + galleryID + ' .fb img');
	var elTitle = $("#" + galleryID + ' .title');
	var title = $("#" + galleryID + ' .thumbnails li').eq(4).attr('title');

	
	// DEFAULT VALUES
	elImg.attr('title', title);
	thumbnails.stop().fadeTo(0, 0.3);
	thumbnails.eq(4).stop().fadeTo(0, 1);
	
	// THUMBNAIL CLICK
	thumbnails.find('a').click(function (e) {
		e.preventDefault();
		
		
		var title = $(this).parent().attr('title');
		var thick = $(this).parent().attr('rel');	
		var rel = $(this).attr('rel');
		var pos = $(this).parent().attr('pos');
		
		thumbnails.stop().fadeTo(0, 0.3).removeClass('active');
		$(this).parent().addClass('active').stop().fadeTo(0, 1);
		elImg.attr({'src': rel, 'title': title });
		elImg.parent().attr('href', thick);
		elImg.parent().attr('pos', pos);
	});
	
	// THUMBNAIL HOVER
	thumbnails.hover(function() {
		$(this).stop().fadeTo(250, 1);
		title = $(this).attr('title');
		elTitle.css('visibility', 'visible').html(title);
	}, function() {
		if ($(this).hasClass('active')) {
			$(this).stop().fadeTo(250, 1);
		} else {
			$(this).stop().fadeTo(250, 0.3);
		}
		elTitle.css('visibility', 'hidden');
	});
	
	// PREVIEW HOVER
	elImg.hover(function() {
		title = $(this).attr('title');
		elTitle.css('visibility', 'visible').html(title);
	}, function() {
		elTitle.css('visibility', 'hidden');
	});
	
		
	$("#" + galleryID + ' .fb').live('click', function(e) {
		e.preventDefault();
		var startPos = parseInt($(this).attr('pos'))-1;
		
		$('#g1'+galleryID).mbGallery({
			cssURL: "css/",
			fadeTime: 0,
			startFrom: startPos,
			maxWidth: 600,
			maxHeight: 480,
			galleryTitle: " ",
			overlayBackground: "#000"
		});
		$('.galleryCloseIcon').html('Zavřít X')	
	});


}




// SCROLL TO TOP 
function scrollToTop() {
	pageHeight = document.getElementById('page').offsetHeight;
	if (pageHeight >= 1200) {
		$('.top').show();
		$("a[href='#head']").click(function() {
		 $("html").animate({ scrollTop: 0 }, "fast");
		 return false;
		});
		
	} else {
		$('.top').hide();
	};
}

//INIT PRODUCT-STAGE LIST
function productListInit(data) {

	$('.product_stage.productset').parent().hide();
	//$('.product_stage.productset').append('<div id="cluetip-waitimage">');

	$.ajax({
	 url: data,
	 type: 'get',
	 cache: false,
	 dataType: 'html',
	 success: function(data) {
		
		$('div.set_wrapper').html(data);

		$('.productset').each( function (index) {
			$(this).find('.set_wrapper').addClass('set-' + index);
			total = $('.set_wrapper.set-'+ index +' .set').length;
			var count = 1;
			// show container if # of products > 0
			if (total > 0) {
				//$('#cluetip-waitimage').remove();
				$('.product_stage.productset').parent().show();				
				$('.product_stage.productset').show();
				//$('.product_stage.productset').parent().show();

				$(this).find('.set_wrapper.set-'+ index +' .set').hide();
				$(this).find('.set_wrapper.set-'+ index +' .set:nth-child(1)').show();

				$(this).find('.set_nav a').live('click', function(e) {
					e.preventDefault();
					$(this).parents().find('.set_wrapper.set-'+ index +' .set:nth-child('+ count +')').hide();
					$(this).attr('class') == 'next' ? count++ : count--;
					(count == total + 1) ? count = 1 : false;
					(count <= 0) ? count = total : false;
					$(this).parents().find('.set_wrapper.set-'+ index +' .set:nth-child('+ count +')').show();
					$('.product_stage .pager').html('[Seite '+ count +' von '+total+']');
				});
				$('.product_stage .pager').html('[Seite '+ count +' von '+total+']');
				$('.product_stage_item:last-child').addClass('last');
				$('.set').eq(1).hide();
		
				Cufon.refresh();
			};

		});
		

		$('.product_detail_layer').cluetip({
		        cluetipClass: 'product_detail_layer',
		        activation: 'click',
		        dropShadow: false,
		        arrows: false,
		        showTitle: false,
		        width: 630,
		        cluezIndex: 101,
		        topOffset: -320,
		        leftOffset: 0,
		        sticky: true,
		        onShow: function(){
		            formData();
		        }
		    });
		
		
	 } //success function end
	});
}


function showThxLayer(){
	
	window.location.hash="thxanc";
	
	$('.thxanc').cluetip({
		cluetipClass: 'newsletter_success',
		activation: 'click',
		dropShadow: false,
		arrows: false,
		showTitle: false,
		local:true,
		positionBy: 'fixed',
		width: 323,
		height: 85,
		cluezIndex: 101,
		topOffset: -83,
		leftOffset: -97,
		sticky: true,
		delayedClose: 6000,
		onShow: function(){
	    	formData();
		}
	});        
	$('a.thxanc').trigger('click');
};


function catalog(linkname)
{
 width=1060;
 height = 660;
 pdw=open(linkname, "linkname","pdw","width=" + width + ",height=" + height + ",toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizeable=no,copyhistory=no,menubar=no");
}

/* Selectbox + Pager Pressefotos */
function showPicture(thema,year,currentpage,currentmax){
	var msg = "DEBUG: ("+thema+"/"+year+"/"+currentpage+"/"+currentmax+")<br/>";
	
	if( thema.match("cindy") ) {
		window.open("http://www.deichmann-presseservice.de/");
		return 0;
	}
	
	var maxperpage = currentmax;
	var max = 0;	
	var page = currentpage;
	if( page<1 ) page=1;
	var iniset = page*maxperpage-maxperpage;
	var offset = page*maxperpage;
	
	msg = msg+"offset:"+offset+"<br/>";
	msg = msg+"iniset:"+iniset;
	
	if( thema || year ){				
		$(".float_block").each(function(index) {	
		    ttmp = $(this).find("h3").text();
		    tid = $(this).find("h3").attr("class");	    
		    // thema & year
		    if( thema && year ){
			    if( (thema.match("Všechny fotografie") || (ttmp && thema.match(ttmp) )) && ( tid && year.match(tid) ) ){	    	
			    	//msg = msg+" true(beide)<br/>";
			    	$(this).show();
			    	max = max+1;
			    }else{
			    	$(this).hide();
			    }	    	
		    }
		    // thema
		    else if( thema && !year ){
			    if( thema.match("Všechny fotografie") || (ttmp && thema.match(ttmp)) ){	    	
			    	//msg = msg+" true(thema)<br/>";
			    	//$(this).show();
			    	max = max+1;
			    	if( max>iniset && max<=offset )
   				    	$(this).show();
   				    else
   				    	$(this).hide();			    	
			    }else{
			    	$(this).hide();
			    }	    	
		    }
		    // year
		    else if( !thema && year ){   	
			    if( tid && year.match(tid) ){	    	
			    	//msg = msg+" true(jahr)<br/>";
			    	$(this).show();
			    	max = max+1;
			    }else{
			    	$(this).hide();
			    }	    		    	
		    }	          
		});
	}else{
		$(".float_block").each(function(index){	
		    $(this).hide();
		});
	}
	
	// render navi
	maxpages = max/maxperpage;
	if( (max%maxperpage)!=0 ){
		maxpages = maxpages+1;
	}
	maxpages = Math.floor(maxpages);
	prev = currentpage-1;
	if( prev<1 ) prev=1;
	next = currentpage+1;
	if( next>maxpages ) next=maxpages;
	
	msg = msg+"<br/>mod:"+(max%maxperpage)+"<br/>";
	msg = msg+"max:"+max+"<br/>";	
	msg = msg+"maxpages:"+maxpages+"<br/>";
	pgp = "";
	if( max>0 ){
		pgp = "<a class=\"prev\" href='javascript:void(0);' onclick='showPicture(\""+thema+"\",\""+year+"\","+prev+","+maxperpage+");'>zpět</a>";
		for(i=1;i<=maxpages;i++){
			msg = msg+" "+i;
			if( i==currentpage ){
				pgp = pgp+"<a class='active' href='javascript:void(0);' onclick='showPicture(\""+thema+"\",\""+year+"\","+i+","+maxperpage+");'>"+i+"</a>&nbsp;";
			}
			else{
				pgp = pgp+"<a href='javascript:void(0);' onclick='showPicture(\""+thema+"\",\""+year+"\","+i+","+maxperpage+");'>"+i+"</a>&nbsp;";			
			}
		}
		pgp = pgp+"<a class=\"next\" href='javascript:void(0);' onclick='showPicture(\""+thema+"\",\""+year+"\","+next+","+maxperpage+");'>dopředu</a>";
	}
	$(".site_pager").html(pgp);
	//$("#debug").html(msg);
};


function showTexte(thema,year,currentpage,currentmax){
	var msg = "DEBUG: ("+thema+"/"+year+"/"+currentpage+"/"+currentmax+")<br/>";
	
	var maxperpage = currentmax;
	var max = 0;	
	var page = currentpage;
	if( page<1 ) page=1;
	var iniset = page*maxperpage-maxperpage;
	var offset = page*maxperpage;
	
	msg = msg+"offset:"+offset+"<br/>";
	msg = msg+"iniset:"+iniset;
	
	if( thema || year ){				
		$(".expand").each(function(index) {	
		    tid = "";
		    ttmp = $(this).find("h2").attr("class");	    
		    // thema & year
		    if( thema && year ){
			    if( (thema.match("Všechny fotografie") || (ttmp && thema.match(ttmp) )) && ( tid && year.match(tid) ) ){	    	
			    	//msg = msg+" true(beide)<br/>";
			    	max = max+1;
			    	if( max>iniset && max<=offset )
   				    	$(this).show();
   				    else
   				    	$(this).hide();
			    }else{
			    	$(this).hide();
			    }	    	
		    }
		    // thema
		    else if( thema && !year ){
			    if( thema.match("Všechny fotografie") || (ttmp && thema.match(ttmp)) ){	    	
			    	//msg = msg+" true(thema)<br/>";
			    	//$(this).show();
			    	max = max+1;
			    	if( max>iniset && max<=offset )
   				    	$(this).show();
   				    else
   				    	$(this).hide();			    	
			    }else{
			    	$(this).hide();
			    }	    	
		    }
		    // year
		    else if( !thema && year ){   	
			    if( tid && year.match(tid) ){	    	
			    	//msg = msg+" true(jahr)<br/>";
			    	max = max+1;
			    	if( max>iniset && max<=offset )
   				    	$(this).show();
   				    else
   				    	$(this).hide();
			    }else{
			    	$(this).hide();
			    }	    		    	
		    }	          
		});
	}else{
		$(".expand").each(function(index){	
		    $(this).hide();
		});
	}
	
	// render navi
	maxpages = max/maxperpage;
	if( (max%maxperpage)!=0 ){
		maxpages = maxpages+1;
	}
	maxpages = Math.floor(maxpages);
	prev = currentpage-1;
	if( prev<1 ) prev=1;
	next = currentpage+1;
	if( next>maxpages ) next=maxpages;
	
	msg = msg+"<br/>mod:"+(max%maxperpage)+"<br/>";
	msg = msg+"max:"+max+"<br/>";	
	msg = msg+"maxpages:"+maxpages+"<br/>";
	pgp = "";
	if( max>0 ){
		pgp = "<a class=\"prev\" href='javascript:void(0);' onclick='showTexte(\""+thema+"\",\""+year+"\","+prev+","+maxperpage+");'>zpět</a>";
		for(i=1;i<=maxpages;i++){
			msg = msg+" "+i;
			if( i==currentpage ){
				pgp = pgp+"<a class='active' href='javascript:void(0);' onclick='showTexte(\""+thema+"\",\""+year+"\","+i+","+maxperpage+");'>"+i+"</a>&nbsp;";
			}
			else{
				pgp = pgp+"<a href='javascript:void(0);' onclick='showTexte(\""+thema+"\",\""+year+"\","+i+","+maxperpage+");'>"+i+"</a>&nbsp;";			
			}
		}
		pgp = pgp+"<a class=\"next\" href='javascript:void(0);' onclick='showTexte(\""+thema+"\",\""+year+"\","+next+","+maxperpage+");'>dopředu</a>";
	}
	$(".site_pager").html(pgp);
	//$("#debug").html(msg);
};

