jQuery.noConflict();
(function($) {
$(document).ready(function(){

	$('input[type=radio]').prettyCheckboxes();
    
	$('.alert').hide();
	
	$('#featuredIntroSection .block').mouseenter(function() {
		var helyzet = $(this).position();
		
		$('#featuredIntroSection #underlay').stop().animate({'left':  helyzet.left }, {duration: 400, easing: 'easeOutCirc'});
	})
	
	$('#featuredIntroSection').mouseleave(function() {
		$('#featuredIntroSection #underlay').stop().animate({'left':  '490px' }, {duration: 400, easing: 'easeOutCirc'});
	})
	
	$('#tabNavLogin a').live('click', function() {
	
		var rel = $(this).attr("rel");
		$('.activeSection').hide().removeClass('activeSection');
		$('#' + rel).show().addClass('activeSection');
	
		$('#tabNavLogin a.current').removeClass('current');
		$(this).addClass('current');
		
		return false;
	});
	
	$('#tabNavAlt a').live('click', function() {
	
		var rel = $(this).attr("rel");
		$('.tabAlt.activeSection').hide().removeClass('activeSection');
		$('#' + rel).show().addClass('activeSection');
	
		$('#tabNavAlt a.current').removeClass('current');
		$(this).addClass('current');
		
		return false;
	});
	
	$.inputtitles = function() {
		$('input:text, input:password').each(function() {

			var usedinput = $(this);		
			var usedinputtitle = $(this).attr('title');
            if(usedinputtitle != '')
			 usedinput.attr('value', usedinputtitle);

			function remove() {
				if(usedinput.val() == usedinputtitle) {
					$(this).val("");
				}
			}

			$(this).blur(function() {
				if(usedinput.val() == "") {
					$(this).val(usedinputtitle);
				$(this).addClass('formError')
				} else {
					$(this).removeClass('formError')
				}
			}).focus(remove)
		
		});
	};
	$.inputtitles(this);
    
    $.loadInputSetEffect = function(){
		$('.openInputSet').click(function() {
			$('.inputSet').slideDown();
		});
		$('.closeInputSet').click(function() {
			$('.inputSet').slideUp();
		});
	}
    $.loadInputSetEffect(this);
	
	$('#domainTableTab a').click(function() {
	
		var rel = $(this).attr('href');
		$('#domainTableTab .active, .tableHolder.active').removeClass('active');
		$(rel).addClass('active');
		$(this).addClass('active');
		return false;
	})

	$('.paketenTable tbody tr:even').addClass('alt');
	
	$('.accTitle').live('click', function() {
		
//		$('.accTitleOpen').removeClass('accTitleOpen');
//		$('.accBlockOpen').removeClass('accBlockOpen');
//		
//		$(this).addClass('accTitleOpen').next().addClass('accBlockOpen');

		if( $(this).hasClass('accTitleOpen') ) {
			$('.accTitleOpen').removeClass('accTitleOpen').next().slideUp('300', function() { $(this).removeClass('addBlockOpen') })
		} else {
			$('.accTitleOpen').removeClass('accTitleOpen').next().slideUp('300', function() { $(this).removeClass('addBlockOpen') })
			$(this).addClass('accTitleOpen').next().slideDown('300', function() { $(this).addClass('accBlockOpen') })
		}
		
	});
	
	$.openAccTitleById = function (id) {
			$('.accTitleOpen').removeClass('accTitleOpen').next().slideUp('300', function() { $('#' + id).removeClass('addBlockOpen') })
			$('#' + id).addClass('accTitleOpen').next().slideDown('300', function() { $('#' + id).addClass('accBlockOpen') })
	}
	$.closeAccTitleById = function (id) {
		$('.accTitleOpen').removeClass('accTitleOpen').next().slideUp('300', function() { $('#' + id).removeClass('addBlockOpen') })
	}
	
	$.loadToolTip = function () {
		$('body').append('<div id="tooltipOverlay"><div id="toolTip"></div></div>');
		
		$('.tooltipTrigger').hover(function() {
			var content = $(this).parent().next('.tooltipContent').html(),
				pos = $(this).offset();
			
			$(this).addClass('active');
				
			$('#tooltipOverlay').show().width($(window).width()).height($(window).height()).children('#toolTip').html('<div class="tooltipArrow"></div>' + content);
			$('#toolTip').css({'left': pos.left + 37, 'top': pos.top - ($('#toolTip').height() / 2 + 20) }).children('.tooltipArrow').css('top', ($('#toolTip').height() / 2 + 20));
			
			return false;
		});
		$('#toolTip').hover(function(){}, function() {
			$(this).parent().hide();
			$(this).parent().children().html('');
			$('.tooltipTrigger.active').removeClass('active');
		});
		
		$('#tooltipOverlay').click(function() {
			$(this).hide();
			$(this).children().html('');
			$('.tooltipTrigger.active').removeClass('active');
		});
	}
	$.loadToolTip(this);
	
	$('.halfInloggen').hover(function() {
	
		$(this).parent().addClass('stateInloggen');
	
	}, function() {
	
		$(this).parent().removeClass('stateInloggen');
	
	});
	
	$('.halfBestel').hover(function() {
	
		$(this).parent().addClass('stateBestel');
	
	}, function() {
	
		$(this).parent().removeClass('stateBestel');
	
	});

	$('.halfUBentIngelogd').hover(function() {
	
		$(this).parent().addClass('stateUBentIngelogd');
	
	}, function() {
	
		$(this).parent().removeClass('stateUBentIngelogd');
	
	});
	
	$('.halfLogOut').hover(function() {
	
		$(this).parent().addClass('stateLogOut');
	
	}, function() {
	
		$(this).parent().removeClass('stateLogOut');
	
	});
	
	$('.cart table tr').hover(function() {
		$(this).children().css('background-color', '#fff');
		
		if( $(this).next().hasClass('inside') ) {
			$(this).next().children().css('background-color', '#fff');
		}
		
	}, function() {
		$(this).children().css('background-color', '#f7f7f7')
		
		if( $(this).next().hasClass('inside') ) {
			$(this).next().children().css('background-color', '#f7f7f7');
		}	
	})
	
	$('.cart table tr.inside').hover(function() {
		$(this).children().css('background-color', '#fff');
		$(this).prev().children().css('background-color', '#fff');		
		
	}, function() {
		$(this).children().css('background-color', '#f7f7f7')
		$(this).prev().children().css('background-color', '#f7f7f7');	
	})
	
	$('.summaryTable tr').hover(function() {
		$(this).children().css('background-color', '#fffde1');
		
		if( $(this).next().hasClass('inside') ) {
			$(this).next().children().css('background-color', '#fffde1');
		}
		
	}, function() {
		$(this).children().css('background-color', '#f7f7f7')
		
		if( $(this).next().hasClass('inside') ) {
			$(this).next().children().css('background-color', '#f7f7f7');
		}	
	})
	
	$('.summaryTable tr.inside').hover(function() {
		$(this).children().css('background-color', '#fffde1');
		$(this).prev().children().css('background-color', '#fffde1');		
		
	}, function() {
		$(this).children().css('background-color', '#f7f7f7')
		$(this).prev().children().css('background-color', '#f7f7f7');	
	})
	
		
	
	$('.selectCaption').live('click', function() {
			$(this).parent().find("ul").toggle();
			return false;
		});

		$('.selectelectList a').live('click', function() {
			var ul = $(this).parent().parent()

			var valueReplace =  $(this).html();
			ul.prev().html(valueReplace);

			ul.parent().prev().val($(this).find("span.value").html())
			ul.parent().prev().trigger('change');

			ul.hide();

			return false;
		});
	
		$.funkySelect = function() {
			/**
			First remove old ones
			**/
			$('.selectHolder').remove();
			
			$('.funkySelect').each(function() {
				
				if(jQuery.browser.msie)
					var selected = $(this).find("option:selected");
				else
					var selected = $(this).find("option[selected]");
				
				if($(this).hasClass('getSelected_' + $(this).attr('name')))
				{
                    if($('#funkySelectSelected_' + $(this).attr('name')).val() != '')
						selected = $(this).find("option[value='" + $('#funkySelectSelected_' + $(this).attr('name')).val() + "']");
					else
						$('#funkySelectSelected_' + $(this).attr('name')).val(selected.val());
				}
					
				var options = $(this).find("option");
		
				var funkySelectHtml = '<div class="selectHolder"></div>';
				$(this).after(funkySelectHtml);
				
				if($(this).hasClass('errorInput'))
					$(this).next('.selectHolder').append('<a class="selectCaption errorInput" href="#">' + selected.text() + '<span class="value">' + selected.val() + '</span></a>');
				else
					$(this).next('.selectHolder').append('<a class="selectCaption" href="#">' + selected.text() + '<span class="value">' + selected.val() + '</span></a>');
				$(this).next('.selectHolder').append('<ul class="selectelectList"></ul>');
		
				options.each(function(){
					$(this).parent().next('.selectHolder').find('.selectelectList').append('<li><a href="#">' + $(this).text() + '<span class="value">' + $(this).val() + '</span></a></li>');
				});
		
				$(this).hide();
		
			});
		};
		$.funkySelect();
		
		$.saveValueFunkySelect = function() {
			$('.funkySelect').change(function(){
				$('#funkySelectSelected_' + $(this).attr('name')).val($(this).val());
			});
		}
		$.saveValueFunkySelect(this);
		

	$('#closePopup').click(function() {
		$('#popupBody').fadeOut(300);
	});

	$('#popupBody').width($(window).width()).height($(document).height());
	$('#popupBody').hide();
	
	/**
	Ajax loader
	**/
	$.showAjaxLoader = function() {
		if($('#ajaxLoader').css('display') == 'none')
			$('#ajaxLoader').css('display', 'block')
		else
			$('#ajaxLoader').css('display', 'none')
	}
    
    $.showAjaxLoaderNew = function(id) {
        if(typeof(id) == 'string')
        {
            if($('#' + id).css('display') == 'none')
    			$('#' + id).css('display', 'block');
    		else
    			$('#' + id).css('display', 'none');
        }
	}
    
    $.showHideAjaxLoader = function(id, show) {
        if(show)
            $('#' + id).show();
        else
            $('#' + id).hide();
    }
	
	/**
	Clear all values of a form
	**/
	$.clear_form_elements = function(ele) {	 
	    $(ele).find(':input').each(function() {
	        switch(this.type) {
	            case 'password':
	            case 'select-multiple':
	            case 'select-one':
	            case 'text':
	            case 'hidden':
	            case 'textarea':
	                $(this).val('');
	                break;
	        }
	    });	 
	}
	
	/**
	Set external domain check
	**/
	$.setExtDomCheck = function() {
		if($('#extDomCheckForm').attr('name'))
		{
            $('#extDomCheckForm').live('submit', function(e) { 
				$.post($('#webPathBase').val() + 'bestellen/?action=extDomCheck', $('#extDomCheckForm').serializeArray(), function(data) {
					window.location.href = $('#webPathBase').val() + 'bestellen';
				}); 
				
				e.preventDefault();
			});
		}
        
	}
	$.setExtDomCheck(this);
});
})(jQuery);

/*
 * --------------------------------------------------------------------
 * jQuery-Plugin - $.download - allows for simple get/post requests for files
 * by Scott Jehl, scott@filamentgroup.com
 * http://www.filamentgroup.com
 * reference article: http://www.filamentgroup.com/lab/jquery_plugin_for_requesting_ajax_like_file_downloads/
 * Copyright (c) 2008 Filament Group, Inc
 * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
 * --------------------------------------------------------------------
 */
 
jQuery.download = function(url, data, method){
	//url and data options required
    if( url && data ){ 
		//data can be string of parameters or array/object
		data = typeof data == 'string' ? data : jQuery.param(data);
		//split params into form inputs
		var inputs = '';
		jQuery.each(data.split('&'), function(){ 
			var pair = this.split('=');
			inputs+='<input type="hidden" name="'+ pair[0] +'" value="'+ pair[1] +'" />'; 
		});
		//send request
		jQuery('<form action="'+ url +'" method="'+ (method||'post') +'">'+inputs+'</form>')
		.appendTo('body').submit().remove();
	};
};

