$(function(){
	$('.quickcontact').HVal({
		errorClass: 'error',
		errorMessage:'Their is an error in our Server Pls Shoot a direct mailt to demo@sabcons.com',
		successMessage:'Thanks. You query has been sent to SABCONS team.',
		ajaxPost: true,
		displayOutput:false,
		disableOnSubmit:true,
		showResult:true
	});
	$('.newsletter').HVal({
		errorClass:'error',
		errorMessage:'Unable to Subscribe you, Please send a mail info@sabcons.com.',
		successMessage:'Subscribed Successfully',
		displayOutput:false,
		disableOnSubmit:true,
		showResult:true
	});
	$('body').append('<div style="position:absolute; display:none; padding:5px; margin-top:-5px; margin-left:0px;" class="popup">PopUp</div>');
	$('body').append('<div id="feedback"><a title="Feedback" href="feedback.php?iframe=true">Feedback</a></div>');
	//$('.coursesch tr td:last-child, .coursesch tr th:last-child').remove();
	$('body').append('<div id="gototop"></div>');
	$('#gototop').css({
		opacity:0.4
	});
	$('#gototop').hover(function(){
		$(this).animate({
			opacity:1
		});
	}, function(){
		$(this).animate({
			opacity:0.4
		});
	});
	$('#gototop').click(function(){
		$('html, body' ).animate({
			scrollTop: 0
		},'fast');
	});
	$(window).scroll(function(){
		if($(window).scrollTop()<10){
			$('#gototop').stop(true, true).fadeOut();
		}else{
			$('#gototop').stop(true, true).fadeIn();
		}
	});
	
	
	$('#feedback').fadeIn();
	$('.quickcontact select').hover(function(e){
		$(this).mousemove(function(e){
			$('.popup').css({
				top:e.pageY+26,
				left:e.pageX-2
			});
		});
		$('.popup').css({
			top:e.pageY+25,
			left:e.pageX
		});
		$('.popup').text('Crl + Click to select SABCONS programs of your interest');
		$('.popup').stop(true, true).fadeIn();
	}, function(){
		$('.popup').stop(true, true).fadeOut();
	});
	$('.hywtwl a').hover(function(e){
		$(this).mousemove(function(e){
			$('.popup').css({
				top:e.pageY+26,
				left:e.pageX-2
			});
		});
		$('.popup').css({
			top:e.pageY+25,
			left:e.pageX
		});
		$('.popup').text('If you don\'t clear PMP in the first attempt, we will..');
		$('.popup').stop(true, true).fadeIn();
	}, function(){
		$('.popup').stop(true, true).fadeOut();
	});
	$('.quickcontact input[type=text], .quickcontact textarea, input[placeholder]').hover(function(e){
		var text = $(this).attr('placeholder');
		$(this).mousemove(function(e){
			$('.popup').css({
				top:e.pageY+26,
				left:e.pageX-2
			});
		});
		$('.popup').css({
			top:e.pageY+25,
			left:e.pageX
		});
		$('.popup').text(text);
		$('.popup').stop(true, true).fadeIn();
	}, function(){
		$('.popup').stop(true, true).fadeOut();
	});
	$('ul.clients li').each(function(){
		$('img', this).load(function(){
			$(this).fadeIn();
		}).error(function(){
			$(this).attr('src','img/clientlogoerror.jpg', function(){
				$(this).load(function(){
					$(this).fadeIn();
				});
			});
		});
	}).hover(function(){
		$('.liov', this).stop(true, true).fadeIn();
	}, function(){
		$('.liov', this).stop(true, true).fadeOut();
	});
	$('form').each(function(){
		if($.trim($(this).attr('action')) == '#' || $.trim($(this).attr('action')) == ''){
			$(this).submit(function(){
				return false;
			});
		}
	});
	$('a').click(function(){
		if($.trim($(this).attr('href'))=='#' || $.trim($(this).attr('href'))==''){
			return false;
		}
	});
	$('.header .nav ul li').each(function(){
		if($(this).children('ul').size() > 0){
			$('a', this).first().addClass('hasdd');
		}
	});
	$('.header .nav ul ul li').each(function(index, element) {
		if($('ul',this).length>0){
			$('a',this).first().removeClass('hasdd').addClass('hasddr');
		}
  });
	$('.header .nav ul li, ul.bcrmul li').hover(function(){
		$('ul', this).first().stop(true, true).slideDown();
		/*$('ul', this).first().stop(true, true).animate({
			opacity: 1.0,
			height: 'toggle',
			marginTop:0
		});*/
	}, function(){
		$('ul', this).first().stop(true, true).slideUp();
/*		$('ul', this).first().stop(true, true).animate({
			opacity: 0,
			height: 'toggle',
			marginTop:-10
		})*/
	});
	function onAfter(curr, next, opts, fwd) {
		var index = opts.currSlide;
		$('#prev,#prev2,#prev3,#prev4,#prev5')[index == 0 ? 'hide' : 'show']();
		$('#next,#next2,#next3,#next4,#next5')[index == opts.slideCount - 1 ? 'hide' : 'show']();
		var $ht = $(this).height();
		$(this).parent().animate({height: $ht});
	}
	$('.smallslider').cycle({
		timeout: 1000,
		fx: 'fade'
	});
    $('.testimonials').after('<div class="testimonial-pager">&nbsp;</div>').cycle({
		fx: 'fade',
		timeout: 8000,
		height: 'fixed',
		pause: 1,
		pager: '.testimonial-pager',
		before: onAfter,
		cleartypeNoBg: true
	});
	$('.programslide').after('<div class="programslide-pager"></div>').cycle({
		timeout: 1000,
		fx: 'scrollHorz',
		cleartypeNoBg: true,
		prev: '.pprev',
		next: '.ppnext'
	});
	$('.programslide, .smallslider').hover(function(){
		$(this).cycle('pause');
	}, function(){
		$(this).cycle('resume');
	});
	$(".slideshow").css("overflow", "hidden");
	$("ul.slides").cycle({
		fx: 'fade',
		pause: 1,
		prev: '.prev',
		next: '.next'
	});
	$(".slideshow2").css("overflow", "hidden");
	$("ul.slides2").cycle({
		fx: 'fade',
		pause: 1,
		prev: '.prev2',
		next: '.next2'
	});
	$('.slideshow, .slideshow2').hover(function(){
		$('.slideheader', this).stop(true, true).slideUp();
	}, function(){
		$('.slideheader', this).stop(true, true).slideDown();
	});
	$('.next2, .next, .prev, .prev2').hover(function(){
		$(this).stop().animate({
			opacity:1
		});
	}, function(){
		$(this).stop().animate({
			opacity:0.5
		});
	});
	$('.acchnav a').each(function() {
		if($(this).hasClass('active')){
			var tardiv = (this.hash).replace("#",".");
			$('.acccont').slideUp();
			$(tardiv).slideDown();
			return false;
		}
    });
	$('.acchnav a').click(function(){
		$('.acchnav a').removeClass('active');
		$(this).addClass('active');
		var tardiv = (this.hash).replace("#",".");
		$('.acccont').slideUp();
		if ($(tardiv).is(':visible')) {
			$(tardiv).slideUp();
		}else{
			$(tardiv).slideDown();
		}
		return false;
	});
	$(".programelink").prettyPhoto({
		default_width: 400,
		default_height: 520,
		social_tools:false
	});
	$("#feedback a").prettyPhoto({
		default_width: 350,
		default_height: 320
	});
});
$(document).ready(function(){
	$("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);
});
/*$(function(){
	$("a[href^=http]").click(function(){
		if(this.href.indexOf(location.hostname) == -1){ 
			window.open(this.href,'_newtab');
			return false;
		}
	});
});*/
