
/*
 * -------------------------------------------------------------------------
 * @file 		dom.js
 * @version 	1.0.0
 * @date 		2010-08-24 12:39:52 +0200 (Tue, 24 Aug 2010)
 * @author 		Matthias Mertiens <mail@mertiens.biz>
 * --------------------------------------------------------------------------
 * Copyright (c) 2010 mertiens. ideas for communication <http://mertiens.biz>
 * -------------------------------------------------------------------------- 
 */

function updateNotepad() {
	$("#notepad-content").fadeOut();
	$("#notepad-content").load("http://frese.de/hochzeitskarten-online-bestellen/notepadajaxpage.html?op=list");
	$("#notepad-content").fadeIn();
}

function addProduct(cardId) {
	if (typeof cardIDs != "undefined") {
		var url = "http://frese.de/hochzeitskarten-online-bestellen/notepadajaxpage.html?op=add&productId=" + cardIDs[currentCardIndex];
	} else {
		var url = "http://frese.de/hochzeitskarten-online-bestellen/notepadajaxpage.html?op=add&productId=" + cardId;
	}
	
	$.get(url, function (myData) {
		if (myData == "DOUBLEITEM") {
			//
		} else {
			updateNotepad();
			setCookie("notepad_data", myData, 30);
		}
		$("#ontowishlist").click(function() { scrollUp(); });
		$("#ontowishlist").html("Merkzettel ansehen");
	});
}

function removeItem(id) {
	$.get("http://frese.de/hochzeitskarten-online-bestellen/notepadajaxpage.html?op=remove&id=" + id, function (myData) {
		
		updateNotepad();
		setCookie("notepad_data", myData, 30);
		
	});
}

function getCookie(c_name) {
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++) {
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function setCookie(c_name,value,exdays) {
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function scrollUp() {
	$("html").scrollTop(0);
	notepadShow();
}



/*function showNotepadInfo(text) {
	var left = $("html").scrollLeft() + (document.body.offsetWidth / 2) - 300;
	var top = $("html").scrollTop() + (document.body.clientHeight / 2) - 50;
	$("#info-popup").css("top", top);
	
	if (getCookie("notepadFirstStart") != "done") {
		text += '<p>Dies ist der erste Artikel, den Sie auf dem Merkzettel vermerken. Sie können den Merkzettel ' + 
				'über einen Klick auf den <img src="/resources/templates/img/notepad_btn_small.png">-Button am ' +
				'oberen Rand der Seite anzeigen.</p>' +
				'<p><a href="javascript:closeNotepadInfo()">Schließen</a> <a href="javascript:scrollUp()">Zum Merkzettel</a>';
		
		setCookie("notepadFirstStart", "done", 1);
		$("#info-popup").html(text);
		$("#info-popup").fadeIn();
	} else {
		$("#info-popup").html(text);
		$("#info-popup").fadeIn();
		$("#info-popup").delay(2000).fadeOut();
	}
}*/

jQuery(document).ready(function($) {

	// initial cookie sync
	updateNotepad();


	$('#card-navi-box').css({ opacity: 0.6 }).hover(
				function() { $(this).animate({ opacity: 1 }); },
				function() { $(this).animate({ opacity: 0.5 }); }
			);



	$("#featured").tabs({event: 'mouseover', fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);






	$.fn.bindHoverEvents = function() {
		var onMouseOutOpacity = 1;//0.82;

		$(this).animate({ opacity: onMouseOutOpacity },250).opacityrollover({
			mouseOutOpacity:   onMouseOutOpacity,
			mouseOverOpacity:  0.82,
			fadeSpeed:         'fast',
			exemptionSelector: '.selected'
		});
	
		return this;					
	}


	$('li', 'menu').hover(
		function() { $(this).addClass('hover'); },
		function() { $(this).removeClass('hover'); }
		);

	$('.external_link').attr('target','_blank');
	
	$('#faq').accordion({ collapsible: true });


	//alert(window.location.hostname);


	/* 	Öffnen externer Links in einem neuen Fenster */
	$('a[href^="http://"]')
		.not('a[href^="http://www.'+window.location.hostname+'/"]')
		.not('a[href^="http://'+window.location.hostname+'/"]')
		.not('a[href^="http://'+window.location.hostname+'"]')
		.attr({target: "_blank"}).addClass("extern");	








$('#slider2').anythingSlider({
   toggleControls : true,
   theme          : 'metallic',
   delay		  : 6000,
   autoPlay		  : true,
   startStopped	  : true,
   buildNavigation: false,
   resizeContents : false
/*
	navigationFormatter : function(i, panel){
    return ['Recipe', 'Quote', 'Image', 'Quote #2', 'Image #2', 'Test'][i - 1];
   }
*/

  });

	$('#picture_navigation ul li').bindHoverEvents();


	
						
				$('img','#slideshow').remove();	
					
				// Initially set opacity on thumbs and add
				// additional styling for hover effect on thumbs
				var onMouseOutOpacity = 1;
				$('#thumbs ul li').opacityrollover({
					mouseOutOpacity:   onMouseOutOpacity,
					mouseOverOpacity:  0.72,
					fadeSpeed:         'fast',
					exemptionSelector: '.selected'
				});
				

					
				// Initialize Advanced Galleriffic Gallery
				var gallery = $('#thumbs').galleriffic({
					delay:                     0,
					numThumbs:                 3,
					preloadAhead:              3,
					enableTopPager:            false,
					enableBottomPager:         false,
					maxPagesToShow:            7,
					imageContainerSel:         '#slideshow',
					controlsContainerSel:      '#controls',
					captionContainerSel:       '#caption',
					loadingContainerSel:       '#loading',
					renderSSControls:          false,
					renderNavControls:         false,
					playLinkText:              'Play Slideshow',
					pauseLinkText:             'Pause Slideshow',
					prevLinkText:              '&lsaquo; Previous Photo',
					nextLinkText:              'Next Photo &rsaquo;',
					nextPageLinkText:          'Next &rsaquo;',
					prevPageLinkText:          '&lsaquo; Prev',
					enableHistory:             false,
					autoStart:                 false,
					syncTransitions:           false,
					defaultTransitionDuration: 900,
					onSlideChange:             function(prevIndex, nextIndex) {
						// 'this' refers to the gallery, which is an extension of $('#thumbs')

						this.find('ul').children()
							.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
							.eq(nextIndex).fadeTo('fast', 1.0);

					},
					onPageTransitionOut:       function(callback) {
						this.fadeTo( 0 , 0.0, callback);
					},
					onPageTransitionIn:        function() {
						this.fadeTo( 0 , 1.0);
					}
				});
		
					
					
					
					
					
					
					
					
					
					
/*
function isEmail(str) {
  return ((str != "") && (str.indexOf("@") != -1) && (str.indexOf(".") != -1));}
*/


function isEmail(s)
{
 var a = false;
 var res = false;
 if(typeof(RegExp) == 'function')
 {
  var b = new RegExp('abc');
  if(b.test('abc') == true){a = true;}
  }

 if(a == true)
 {
  reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
                   '(\\@)([a-zA-Z0-9\\-\\.]+)'+
                   '(\\.)([a-zA-Z]{2,4})$');
  res = (reg.test(s));
 }
 else
 {
  res = (s.search('@') >= 1 &&
         s.lastIndexOf('.') > s.search('@') &&
         s.lastIndexOf('.') >= s.length-5)
 }
 return(res);
} 
					
					
						
/* 	Easy Form Validation   -------------------------------------------------------------					 */
										
$.fn.bindForm = function(link) {

	var cf = this;

	var submitButtonOld = $('#submitButton',cf).css('display','none');
	var submitButton = $('<a href="#" class="button gradient">' + ( $(submitButtonOld).val() || $(submitButtonOld).text() ) + '</a>').appendTo( $(submitButtonOld).parent() );


	$(submitButton).bind('click', function(event) {
	
			event.preventDefault();
	 	
 			var goSubmit = true;
	 			
	 			
	 		$('.required',cf).each(function(){
	 				
	 				
	 			var elid = $(this).attr('id');	

				$(this).val( $.trim($(this).val()) );
	 				
	 				 						 			
	 			if( $(this).val()=="" || ( $(this).hasClass('email') && !isEmail( $(this).val() )) || ( $(this).attr('type')=='checkbox' && !$(this).attr('checked') ) ) {
	 				
	 				var parentP = $(this).parent('p');
	 				
	 				var errorMsg = $('<span class="errormsg">Bitte ausfüllen!</span>');
	 				
	 				if( $(this).hasClass('email') && !isEmail( $(this).val()) )
	 				var errorMsg = $('<span class="errormsg">Bitte tragen Sie eine gültige Mail-Adresse ein!</span>');
	 				
	 				
	 				if( $('.errormsg',parentP).length == 0)
	 				parentP.addClass('error').append( $(errorMsg).hide().fadeIn(800) );
	 					
/* 	 				$('label[for="' + elid + '"]').addClass("error"); */

/* 	 				$(this).addClass("error") */
	 				$(this).keyup(function() { 
/* 	 							$(this).removeClass("error").parent('p') */

					

								if( ($.trim($(this).val())!="" &&  !( $(this).hasClass('email') && !isEmail( $(this).val() ) ) )	 || 	( $(this).attr('type')=='checkbox' && $(this).attr('checked') )  ) {
	 							parentP.removeClass("error");
	 							errorMsg.remove();
	 							}
/* 	 							$('label[for="' + elid + '"]').removeClass("error"); */
	 						});
	 				
	 				goSubmit = false;
	 					
	 				} // /if	
	 			});
	 			
	 			
	 		
	 		
	 		// Formular senden ---------------------		
	 		if( goSubmit ) {	

				submitButton.replaceWith('<img id="loading" src="/resources/img/ajax-loader.gif" alt="Loading" >');

	 			var formulardata = $(cf).serialize();
	 			var url = $(cf).attr('action'),
	 				on_success = function() { $('#loading')
	 												.replaceWith('<p class="gesendet">Die E-Mail wurde versendet.</p>'); 
	 												$('fieldset,#hinweis',cf).not('.buttonbox').animate({ opacity: 0.2 }); 
	 												$(link).unbind().click(function(){return false;}).css({ opacity: 0.3 }); 
	 												};
	 												
	 			//alert(formulardata);									
	 			$.ajax({ 	
	 					type: 'POST',
	 					url: url, 
	 					data: formulardata, 
	 					success: on_success 
	 					});

	 			}
	 				
			});

	return this;
} 
/* fct bindForm 	--------------------------------------------------------------------------------------					 */			


$('#ContactFormSet').bindForm(null);






/* Suche im Header animieren
 -------------------------------------------------------------------------------------- */
	var query = $('#query');
	var searchbutton = $('#searchbutton');
	query.pos = query.position();
	
	
	$(query).animate({ top: -30,opacity: 0.2 }, 50);
	$(searchbutton).animate({ opacity: 0.2 }, 50)
		.mouseover(function(){ 
					//if( $('#query').css('top') <= 0 ) {
							$(query).animate({ top: query.pos.top, opacity: 1 }, 250).focus();
							$(this).animate({ opacity: 0.5 }, 200);
					//	}
						});
		$('#search').mouseleave(function() {
				$(query).animate({ opacity: 0.2 });
				$(searchbutton).animate({ opacity: 0.2 }, 300);
		});
		
		$(query).bind('keyup',function() { $(this).animate({ opacity: 1 }, 200); })
				.bind('blur',function() { $(this).animate({ opacity: 0.2 }, 200); });
	
			




	$("#notepadbutton").animate({ opacity: 0.3 }, 200);
	
	$("#notepadbutton").mouseover(function() {
		$("#notepadbutton").animate({ opacity: 0.5 }, 200);
	});
	
	$("#notepadbutton").mouseleave(function() {
		$("#notepadbutton").animate({ opacity: 0.3 }, 300);
	});
	
	$("#notepadbutton").click(function() {
		notepadShow();
	});
	
	notepadHide();
});

function notepadShow() {
	$("#notepad-box").show();
	$("#notepad-box").animate({ top: 0 }, 200);
}

function notepadHide() {
	var myheight = $("#notepad-box").css("height");
	try {
		myheight = myheight.replace("px", "");
		myheight = myheight * (-1);
		$("#notepad-box").animate({ top: myheight }, 200);
		$("#notepad-box").fadeOut();
	} catch (e){}
}

