/*P&P javascript handling*/

var baseUrl = window.location.href.split('#')[0];

$(document).ready(function(){
	if(!Modernizr.input.placeholder){
			/*$('input, textarea').live('focus',function(){*/
				$('input, textarea').each(function(){
					if($(this).val()=='' && $(this).attr("placeholder")!=''){
						$(this).val($(this).attr('placeholder'));
						$(this).focus(function(){
						if($(this).val()==$(this).attr('placeholder')){
							$(this).val('');
							}
						});
						$(this).blur(function(){
							if($(this).val()=='') $(this).val($(this).attr('placeholder'));
						});
					}
				});
			/*});*/
		}

		$('.main-menu a').each(function(){
			$(this).hover(function(){
				if(!$(this).hasClass('active')){
					$(this).addClass('active');
					$(this).attr('id','adr');
				}
			},function(){
				if($(this).attr('id')!=undefined){
					$(this).removeClass('active');
				}
				$(this).removeAttr('id');
			});
		});

	if($.browser.msie!=true){
		history.pushState('', document.title, baseUrl);
	}
	
	
	/*if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
		$('.main-menu a').tappable({
		callback : function(){alert('Mammamia!')},
		touchDelay:   100		
		});
	}
	*/
	
	$('.main-menu a').tappable(function(e){
		e.preventDefault();
		elementClicked = $(this).attr("href").split('/')[1]!='' ? $(this).attr("href").split('/')[1] : 'top';
		var destination = $('a[name='+elementClicked+']').offset().top;
		//Cycle to first index
		if(elementClicked=='szolgaltatasok' || elementClicked=='referenciak'){
			$('#cb1 .services-box a').removeAttr('class');
			$('#cbc1').cycle(0);
			$('#cbc2').cycle(0);
		}
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 400,
		function(){
			if($.browser.msie!=true){
				history.replaceState('', document.title, '#'+elementClicked);
			}else{
				window.location.href=baseUrl+'#'+elementClicked;
			}
		});	
	
	})
	
	
	
	/*Advancing scrollto handling*/
	/*$('.main-menu a').click(function(e) {
		e.preventDefault();
		elementClicked = $(this).attr("href").split('/')[1]!='' ? $(this).attr("href").split('/')[1] : 'top';
		var destination = $('a[name='+elementClicked+']').offset().top;
		//Cycle to first index
		if(elementClicked=='szolgaltatasok' || elementClicked=='referenciak'){
			$('#cb1 .services-box a').removeAttr('class');
			$('#cbc1').cycle(0);
			$('#cbc2').cycle(0);
		}
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 400,
		function(){
			if($.browser.msie!=true){
				history.replaceState('', document.title, '#'+elementClicked);
			}else{
				window.location.href=baseUrl+'#'+elementClicked;
			}
		});
	});*/

	$('a[rel="menuitem-1"],a[rel="menuitem-5"]').click(function(e){
		e.preventDefault();
		elementClicked = $(this).attr("href").split('/')[1]!='' ? $(this).attr("href").split('/')[1] : 'top';
		var destination = $('a[name='+elementClicked+']').offset().top;
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 400,
		function(){
			if(!$.browser.msie){
				history.replaceState('', document.title, '#'+elementClicked);
			}else{
				window.location.href=baseUrl+'#'+elementClicked;
			}
		});

		/*$('.main-menu a').each(function(){
			$(this).removeClass('active');
		});*/
	});



	$('#cbc1').cycle({
	   speed:  500,
	   fx: 'scrollHorz',
	   timeout: 0,
	});

	$('#cbc2').cycle({
	   speed:  500,
	   fx: 'scrollHorz',
	   timeout: 0,
	   prev:'#ref-prev',
	   next:'#ref-next'
	});

	$('#ref-prev, #ref-next').click(function(e){
		e.preventDefault();
	});

	//Szolgaltatasok JS
	$('#cb1 .services-box a').each(function(k){
		$(this).tappable(function(e){
			e.preventDefault();
			$('#cb1 .services-box a').removeAttr('class');
			$(this).addClass('current');
			$('#cbc1').cycle(k+1);
			history.replaceState('', document.title, '#szolgaltatasok-'+eval(k+1));
		});
	});


});


