/**                                                                                                                                                                                              
 * clever + zöger gmbh                                                                                                                                                                           
 * http://www.clever-zoeger.de                                                                                                                                                                   
 * @author Ronny Hempel <rhempel@clever-zoeger.de>                                                                                                                                           
 * @version $Id: pp.js 36 2011-02-09 13:02:46Z rhempel $                                                                                                                                                                                
 * $HeadURL: https://svn.clever-zoeger.de/plaketten-petersen/plaketten-petersen.de/trunk/skin/frontend/default/default/js/pp.js $                                                                                                                                                                                   
 * $LastChangedBy: rhempel $                                                                                                                                                                            
 * $LastChangedRevision: 36 $                                                                                                                                                                       
 * $LastChangedDate: 2011-02-09 14:02:46 +0100 (Mi, 09. Feb 2011) $                                                                                                                                                                            
 */
function checkUserLoginInputs() {
	if (jQuery('#mini-password').val() != '') {
		jQuery('#mini-password').addClass('box-empty');
		jQuery('#mini-password').removeClass('password-default');
	} else {
		jQuery('#mini-password').addClass('password-default');
		jQuery('#mini-password').removeClass('box-empty');
	}
	if (jQuery('#mini-login').val() != '') {
		jQuery('#mini-login').addClass('box-empty');
		jQuery('#mini-login').removeClass('benutzer-default');
	} else {
		jQuery('#mini-login').addClass('benutzer-default');
		jQuery('#mini-login').removeClass('box-empty');
	}
}

function initPasswortInput() {
	checkUserLoginInputs();
	jQuery('#mini-password').click(function() {
		jQuery('#mini-password').addClass('box-empty');
		jQuery('#mini-password').removeClass('password-default');
	});
	
	jQuery('#mini-password').focus(function() {
		jQuery('#mini-password').addClass('box-empty');
		jQuery('#mini-password').removeClass('password-default');
	});
	jQuery('#mini-password').blur(function() {
		checkUserLoginInputs();
	} );
	jQuery('#mini-password').change(function() {
		checkUserLoginInputs();
	} );
	jQuery('#mini-login').click(function() {
		jQuery('#mini-login').addClass('box-empty');
		jQuery('#mini-login').removeClass('benutzer-default');
	});
	jQuery('#mini-login').blur(function() {
		checkUserLoginInputs();
	} );
	jQuery('#mini-login').change(function() {
		checkUserLoginInputs();
	} );
}

var is_in_menu = false;
var menuObj = null;

function closeMenuHover(obj) {
	//jQuery(obj).find('div.subnav').dequeue().stop().fadeOut('fast');
    jQuery(obj).find('div.subnav').dequeue().stop().fadeOut(500);//.css('opacity',0);
}

function initMenuHover(obj) {
	jQuery(obj).find('.subnav').dequeue().stop().css('display','none').css('opacity',1).delay(500).fadeIn(500);
	menuObj = jQuery(obj).find('.subnav');
}

function initContentMenu() {
    jQuery('.navhg2 ul.topcontentmenu li.level0').bind("mouseenter", function () {
	
	//closeMenuHover(this);
	initMenuHover(this);
    });
	
    jQuery('.navhg2 ul.topcontentmenu li.level0').bind("mouseleave", function () {
	        is_in_menu = false;
	        closeMenuHover(this);
    });
	
}

function initOnestepcheckout() {
	if (jQuery('#billing_address_list #customerart').length) {
		jQuery('#billing_address_list #customerart').css('display','none');
		jQuery('#billing_address_list #customerart option').each(function() {
			var el = jQuery(this);
			if (el.attr('selected')) {
				jQuery('#billing_address_list #customerart').after('<input class="customerartradio" checked="checked" type="radio" name="customerart-r" value="'+el.val()+'"/> <span class="kundenarttext">'+el.html()+'</span>');
			} else {
				jQuery('#billing_address_list #customerart').after('<input class="customerartradio" type="radio" name="customerart-r" value="'+el.val()+'"/> <span class="kundenarttext">'+el.html()+'</span>');
			}	
		});
		jQuery('#billing_address_list .customerartradio').click(function() {
			var el = jQuery(this);
			jQuery('#billing_address_list #customerart').val(el.val());
			//alert(document.forms.onestepcko.elements[1].value);
		});
	}
}

function setFeedbackAjaxform() {
		            jQuery('#formularForm').ajaxForm({
		            	success: function(responseText, statusText, xhr, $form) {
		            		jQuery('#fancybox-content div').html(responseText);
		            		setFeedbackAjaxform();
		            	}
		            	
		            });	     

}

function initFeedbackform() {

/**/
	
	if (jQuery('.feedbacklink').length) {

		jQuery('.feedbacklink').fancybox({
			'autoScale'	:	false,
			'width':400,
            'height':300,
            'titleShow' : false,
			ajax : {
				type : "GET",
			},
			onComplete : function(){
			    jQuery('span.field-row #betreff').val(document.title);
			    setFeedbackAjaxform();
			},

			
		});
	}
	
}

function initTexteAnsehen() {
	if (jQuery('a.showtext').length) {
		jQuery('a.showtext').click(function() {
			var text = jQuery(this).parent().find('span.textview').html();			
			text = '<div style="padding: 20px; line-height: 22px;">'+text+'</div>';
			jQuery.fancybox(text);			
		});
	}
}

function openFeedbackform() {


	
}

function initDetailViewElements() {
	if (jQuery('.product-view .band .bandselect select.bandwahl').length) {
		jQuery('.product-view .band .bandselect select.bandwahl').msDropDown();
	}
}

function initReward() {
	if (jQuery('.checkoutcontainer .discount #coupon_code_points_qty').length) {
		jQuery('.checkoutcontainer .discount .rewardsubmit').click(function() {
			jQuery.ajax({
				type: 'POST',
				url: rewardurl,
				data: {
					points_to_be_used: jQuery('.checkoutcontainer .discount #coupon_code_points_qty').val()
				},
				success: function(data) {
					self.location.reload();
				}
			});
		});
	}
	
	if (jQuery('.checkoutcontainer .discount .rewarddelete').length) {
		jQuery('.checkoutcontainer .discount .rewarddelete').click(function() {
			jQuery.ajax({
				type: 'POST',
				url: rewardurl,
				data: {
				},
				success: function(data) {
					self.location.reload();
				}
			})
		});
	}
}

function initMore() {
    if (jQuery('.moreinfobtn').length) {
	jQuery('.moreinfobtn').click(function() {
	    var rel = jQuery(this).attr('rel');
	    jQuery('div.'+rel).toggle();
	    if (jQuery('div.'+rel).css('display') == 'block') {
		jQuery('span.'+rel).html('&lt;&lt; weniger');
	    } else {
		jQuery('span.'+rel).html('&gt;&gt; mehr');
	    }
	});
	
	jQuery('div.moreinfo').css('display','none');
    }
}

jQuery(document).ready(function(){
	initPasswortInput();
	initContentMenu();
	initOnestepcheckout();
	initFeedbackform();
	initDetailViewElements();
	initTexteAnsehen();
	initReward();
	initMore();
});

