/* Google analytics */

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-23155600-1']);
_gaq.push(['_setDomainName', '.shaastra.org']);
_gaq.push(['_trackPageview']);

(function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

/* End Google Analytics*/
var headerNavText = {"top-home":"Home", "top-event":"Events", "top-hospitality":"Hospitality", "top-sponsorship":"Sponsorship", "top-blog":"Blog"};

$(document).ready( function(){ 
	
	setBannerSlideShow();
	setDock();
	setRegisterBtn();

	$("#header-spons-trans").cycle({cleartype:1});
	
	$("#header-nav a").mouseover(function() {
			$('#header-toplinks-drawer').css({left:'230px'});
			$('#header-toplinks-drawer-text').html(headerNavText[$(this)[0].id]);
			$('#header-toplinks-drawer').stop().animate({'left':'0px'}, 'fast');
	});
	$("#header-nav a").mouseout(function() {
			$('#header-toplinks-drawer').css({left:'230px'});
			$('#header-toplinks-drawer-text').html("Shaastra '10");
			$('#header-toplinks-drawer').stop().animate({'left':'0px'}, 'fast');
	});
	
	// Color Bars on menu items
	var color = ["#395b5d","#57554f", "#7b8153", "#57554f", "#8e6753","#57554f"];
	var c=0;	
	$('#block-menu-menu-events div.content>ul.menu>li').each(function() {
		$(this).prepend('<div class="menuItemColorBar"></div>');
		$(this).children(".menuItemColorBar").css('background-color',color[c]);
		$(this).children("ul").css('border-top-color',color[c]);
		c++; if(c==color.length) {c=0;}
	});
	// -------------
	var parent;
	$('#block-menu-menu-events div.content>ul.menu>li>a').each(function() {	
	$(this).mouseenter(function() {
		parent = $(this).parent();
		//parent.children("ul").css("z-index",17);
		parent.stop(true,true).animate({left:'-10px',paddingRight:'10px'},{ duration:'fast'}).css('overflow','visible');
		parent.children("ul").stop(true,true).animate({height:"show",opacity:"show"},{ duration:'fast'})
	})
	});
	$('#block-menu-menu-events div.content>ul.menu>li').mouseleave(function() {		
		//$(this).children("ul").css("z-index",13);
		$(this).children("ul").stop(true,true).animate({height:"hide",opacity:"hide"},{ duration:'fast'});
		$(this).stop(true,true).animate({left:'0px',paddingRight:'0px'},{ duration:'fast'}).css('overflow','visible')
	});
	
	// submenus
	
	$('#block-menu-menu-events div.content>ul.menu>li>ul.menu>li').each(function() {	
	$(this).hover(function() {
		//$(this).children("a").stop(true,true).animate({paddingLeft:'-=5px'},'fast').css('overflow','visible');
		$(this).children("ul").stop(true,true).animate({height:"show", opacity:"show"},300).css('overflow','visible');
	}, function() {
		//$(this).children("a").stop(true,true).animate({paddingLeft:'+=5px'},'fast').css('overflow','visible');
		$(this).children("ul").stop(true,true).animate({height:"hide", opacity:"hide"},200).css('overflow','visible');
	})
	})
	// -----------
});

function setDock() {
	$('#dock2').Fisheye({
		maxWidth: 15,
		items: 'a',
		itemsText: 'span',
		container: '.dock-container2',
		itemWidth: 50,
		proximity: 40,
		alignment : 'left',
		valign: 'bottom',
		halign : 'center'
	});
}

function setBannerSlideShow() {
	
	$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
		$(pager).find('a').removeClass('activeSlide') 
			.filter('a:eq('+currSlideIndex+')').addClass('activeSlide'); 
	};	

	$('#slide-images').cycle({
		timeout:4000,
		pager:'#slideshowLEDs',
		next:'#slideright',
		prev:'#slideleft',
		pagerAnchorBuilder: function(idx, slide) { 
			return '#LED' + (idx+1);
		} 
	});
}

var shakeInterval=0, registerBtnLeft=0, registerBtnTop=0;

function setRegisterBtn() {
	registerBtnLeft = parseFloat($('#registerBtn').css("left").substring(0, $('#registerBtn').css("left").length-2));
	registerBtnTop = parseFloat($('#registerBtn').css("top").substring(0, $('#registerBtn').css("top").length-2));
	
	setInterval('registerBtnTimer()', 5000);
	
}
var registerBtnFlag = 1, registerBtnMotion=1;
function registerBtnShake() {
	if (registerBtnMotion>0) {
		var newleft=registerBtnLeft + 4*registerBtnFlag + 'px';
		$('#registerBtn').animate({'left':newleft},150);
	}
	else if (registerBtnMotion<0) {
		var newtop=registerBtnTop + 2*registerBtnFlag + 'px';
		$('#registerBtn').animate({'top':newtop},150);
	}	
	registerBtnFlag*=-1;
}
function registerBtnTimer() {
	shakeInterval = setInterval('registerBtnShake()', 160);
	setTimeout("registerBtnStopMotion()",1500);
}

function registerBtnStopMotion () {
	clearInterval(shakeInterval); registerBtnMotion*=-1;
}

