// xorus template main javascript file

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
function checkVersion()
{
  var ver = getInternetExplorerVersion();

  if ( ver > -1 )
	return 1;
  else
	return 0;

}
$(function(){

$("img.icon").mouseover(function(e){
//topic = this.alt;
//imghover = document.createElement('div');
//imghover.setAttribute('class','imghover');
//imghover.innerHTML = topic;
//$(this).parent().parent().prev().find('img').animate({width:'70',height:'70'},50);
//$(this).parent().parent().next().find('img').animate({width:'70',height:'70'},50);
var ipar = $(this).parent();
ipar.find('div').css({'display':'block'});
$(this).stop().animate({width:'80',height:'80'},50);

});
$("a.cms-actionlogin").bind({click: function(e){ e.preventDefault(); return false; }});
$('#logincloser').click(function(){
$('#logincontainer').fadeOut(200);
});
$('.cms-actionbarPageItem > a').click(function(){
if(this.innerHTML=='Login'){
$('#logincontainer').fadeIn(300);
}
});
$("img.icon").mouseout(function(e){
var ipar = $(this).parent();
ipar.find('div').css({'display':'none'});
//$('#imghover').remove();
//$(this).parent().parent().prev().find('img').animate({width:'60',height:'60'},50);
//$(this).parent().parent().next().find('img').animate({width:'60',height:'60'},50);
$(this).stop().animate({width:'60',height:'60'},150);
});
$('.dragbar').mouseover(function(){

switch(this.innerHTML){
case 'Videos':drag = '#draglink';break;
case 'Downloads':drag = '#dragdownload';break;
case 'Archives':drag = '#dragarchives';break;
}
closedrag = '.drag:not('+drag+')';
$(closedrag).animate({height:'0'},100);
$(drag).animate({height:$(drag).find('a').size()*18},200);

});

var news,newslen,newsi,stopnews=0;

// function to automatic move of the news box
$(function(){

news = $('.news');
newslen = news.length-1;
news[0].style.marginLeft="210px";
news[0].style.display = 'block';
$(news[0]).animate({marginLeft:'0'},150);
newsi=0;

changeNews();
});

function changeNews(){


$('#newsid').text('['+(newsi+1)+'/'+newslen+']');
$(news[newsi]).delay(3000).animate({marginLeft:'-210'},150,function(){
if(stopnews==0){
this.style.display='none';
newsi++;

if(newsi>=newslen){
newsi = 0; 
}

news[newsi].style.marginLeft="210px";
news[newsi].style.display = 'block';
$(news[newsi]).animate({marginLeft:'0'},150);


changeNews();
}

});
}

$('#newsright').click(function(){

$('.news').stop();
stopnews = 1;
$('.news').css({display:'none',marginLeft:'0'});
moveright();
});

function moveright(){
newsi++;
if(newsi>=newslen){
newsi = 0; 
}
$('#newsid').text('['+(newsi+1)+'/'+newslen+']');
$(news[newsi]).css({display:'block'});
}
$('#newsleft').click(function(){

$('.news').stop();
stopnews = 1;
$('.news').css({display:'none',marginLeft:'0'});
moveleft();
});
function moveleft(){
newsi--;
if(newsi<0){
newsi = newslen-1;
}
$('#newsid').text('['+(newsi+1)+'/'+newslen+']');
$(news[newsi]).css({display:'block'});
}
$(function(){
// function to create MENUBAR automatically for cms $MENUBAR - hard coded only till depth3 for only 7 depth1 elements
var depth1 = $('.depth1:first > li');
var depth1len = depth1.length;
var i,j,k;
for(i=0;i<depth1len;i++){
var submenu = document.getElementById('submenu'+i);

var depth2 = $(depth1[i]).find('.depth2:first > li');//depth1.getElementsByTagName('ul');
var depth2len = depth2.length;
if(submenu.id=='submenu0'){
var me_second = document.createElement('div');
me_second.setAttribute('id','menuevent_second');
submenu.appendChild(me_second);
submenu = document.getElementById('menuevent_second');
}
for(j=0;j<depth2len;j++){	// This is for each mainmenu

var depth3 = $(depth2[j]).find('.depth3:first > li');
var depth3len = depth3.length;

if(depth3len<8){	// if depth3 elements are more than 7 then create another menubox element adjacent to it with next 7 elements

// CREATE MENUBOX
var menubox = document.createElement('div');
menubox.setAttribute('class','menulevel_box');
//CREATE MENUTOP DEPTH 2
var menutop = document.createElement('div');
menutop.setAttribute('class','menulevel_top');
menutop.innerHTML = '<a href='+ $(depth2[j]).find('a:first').attr('href') +'>' + $(depth2[j]).find('a:first > div').html() + '</a>';
menubox.appendChild(menutop);

// CREATE MENU MIDDLE
var menumiddle = document.createElement('div');
menumiddle.setAttribute('class','menulevel_middle');

for(k=0;k<depth3len;k++){
// CREATE MENUTOP DEPTH 3
var menuelt = document.createElement('div');
menuelt.setAttribute('class','menulevel_elt');
menuelt.innerHTML = '<a href='+$(depth3[k]).find('a:first').attr('href')+'>'+$(depth3[k]).find('a:first > div').html() + '</a>';
menumiddle.appendChild(menuelt);
}
var menubottom = document.createElement('div');
menubottom.setAttribute('class','menulevel_bottom');
menubox.appendChild(menumiddle);
menubox.appendChild(menubottom);
submenu.appendChild(menubox);
if(checkVersion()){
$(menutop).css({'background':'url(../images/main/menulevel_top.jpg) no-repeat','height':'42px','width':'180px','color':'black','line-height':'50px','font-size':'12px'});
$(menumiddle).css({'background':'url("../images/main/menulevel_middle.png") repeat-y','width':'180px'});
$(menubottom).css({'background':'url("../images/main/menulevel_bottom.png") no-repeat','height':'21px','width':'180px'});
}
}
else{

// CREATE MENUBOX
var menubox = document.createElement('div');
menubox.setAttribute('class','menulevel_box');
//CREATE MENUTOP DEPTH 2
var menutop = document.createElement('div');
menutop.setAttribute('class','menulevel_top');
menutop.innerHTML = '<a href='+ $(depth2[j]).find('a:first').attr('href') +'>' + $(depth2[j]).find('a:first > div').html() + '</a>';
menubox.appendChild(menutop);

// CREATE MENU MIDDLE
var menumiddle = document.createElement('div');
menumiddle.setAttribute('class','menulevel_middle');

for(k=0;k<7;k++){
// CREATE MENUTOP DEPTH 3
var menuelt = document.createElement('div');
menuelt.setAttribute('class','menulevel_elt');
menuelt.innerHTML = '<a href='+$(depth3[k]).find('a:first').attr('href')+'>'+$(depth3[k]).find('a:first > div').html() + '</a>';
menumiddle.appendChild(menuelt);
}
var menubottom = document.createElement('div');
menubottom.setAttribute('class','menulevel_bottom');
menubox.appendChild(menumiddle);
menubox.appendChild(menubottom);
submenu.appendChild(menubox);
if(checkVersion()){
$(menutop).css({'background':'url(../images/main/menulevel_top.jpg) no-repeat','height':'42px','width':'180px','color':'black','line-height':'50px','font-size':'12px'});
$(menumiddle).css({'background':'url("../images/main/menulevel_middle.png") repeat-y','width':'180px'});
$(menubottom).css({'background':'url("../images/main/menulevel_bottom.png") no-repeat','height':'21px','width':'180px'});
$(menubox).css({'float': 'left','font-weight': 'bold','margin-left': '59px','text-align': 'center','width': '180px'});
}
// creating adjacent box

// CREATE MENUBOX
var menubox = document.createElement('div');
menubox.setAttribute('class','menulevel_box');
//CREATE MENUTOP DEPTH 2
var menutop = document.createElement('div');
menutop.setAttribute('class','menulevel_top');
menutop.innerHTML = '<a href='+ $(depth2[j]).find('a:first').attr('href') +'>' + $(depth2[j]).find('a:first > div').html() + '</a>';
menubox.appendChild(menutop);

// CREATE MENU MIDDLE
var menumiddle = document.createElement('div');
menumiddle.setAttribute('class','menulevel_middle');

for(k=7;k<depth3len;k++){
// CREATE MENUTOP DEPTH 3
var menuelt = document.createElement('div');
menuelt.setAttribute('class','menulevel_elt');
menuelt.innerHTML = '<a href='+$(depth3[k]).find('a:first').attr('href')+'>'+$(depth3[k]).find('a:first > div').html() + '</a>';
menumiddle.appendChild(menuelt);
}
var menubottom = document.createElement('div');
menubottom.setAttribute('class','menulevel_bottom');
menubox.appendChild(menumiddle);
menubox.appendChild(menubottom);
submenu.appendChild(menubox);
if(checkVersion()){
$(menutop).css({'background':'url("../images/main/menulevel_top.jpg") no-repeat','height':'42px','width':'180px','color':'black','line-height':'50px','font-size':'12px'});
$(menumiddle).css({'background':'url("../images/main/menulevel_middle.png") repeat-y','width':'180px'});
$(menubottom).css({'background':'url("../images/main/menulevel_bottom.png") no-repeat','height':'21px','width':'180px'});
}
}
if(checkVersion()){
$(menubox).css({'float': 'left','font-weight': 'bold','margin-left': '59px','text-align': 'center','width': '180px'});
}
}
//alert(depth2);


}


});

$('#menulevel_scroll_l').click(function(){
var mleft = (document.getElementById('menulevel_innerbox').style.marginLeft).split("px");
mleft = mleft[0];
if(!mleft)
	mleft=0;
if(mleft<0){
mleft = parseInt(mleft) + 240;
$("#menulevel_innerbox").animate({marginLeft:mleft},{duration:'100',specialEasing:{height:'swing'}});
}
});

$('#menulevel_scroll_r').click(function(){
var boxSize = $('.menulevel_box:visible').size() - 4;
boxSize = boxSize * -240 ;
var mleft = (document.getElementById('menulevel_innerbox').style.marginLeft).split("px");
mleft = mleft[0];
if(!mleft)
	mleft=0;

if(mleft>boxSize){
mleft = parseInt(mleft) - 240;
$("#menulevel_innerbox").animate({marginLeft:mleft},{duration:'100',specialEasing:{height:'swing'}});
}
});

$("#menulevel_closer").click(function(){

$("#menulevel_container").animate({height:'0',opacity:'0'},{duration:'300',specialEasing:{height:'swing'},complete:function(){$("#menulevel_container").css({display:'none'});}});

});
function show_circles(){
cle_i=70;
$('.menuevents').each(function(index){
$(this).animate(
	{left:cle_i},
	{duration:1300,specialEasing:{height:'swing'},complete:function(){

	if(index==8){
		$('.menuevents:even').animate({top:'140'},200);
		$('.menuevents:odd').animate({top:'220'},200);
		}

	}
	});
	cle_i+=110;
});
}

$('.menuevents').click(function(){
$('#menuevent_first').css({display:'none'});
switch(this.id){
case '0':me_i=0;break;
case '1':me_i=0;break;
case '2':me_i=2;break;
case '3':me_i=3;break;
case '4':me_i=4;break;
case '5':me_i=5;break;
case '6':me_i=6;break;
case '7':me_i=6;break;
case '8':me_i=6;break;
}
me_i*=-240;
$('#menulevel_innerbox').css({marginLeft:me_i});
$('#menuevent_second').css({display:'block'});
});
$("img.icon").click(function(){
switch(this.alt){
case 'Events':show_circles();id=0;break;
case 'Guest Lectures':id=1;break;
case 'Workshops':id=2;break;
case 'Infotainment':id=3;break;
case 'Exhibitions':id=4;break;
case 'Crossfire':id=5;break;
case 'Highlights':id=6;break;
}
//alert('ghg');
id = "#submenu"+id;
$(this).animate({opacity:'0.3'},30);
$(this).animate({opacity:'1.0'},800);

if($(id).find('div').html()){
$("#menulevel_container").css({display:'block'});
$("#menulevel_container").animate({height:'0',opacity:'0'},{duration:'5',specialEasing:{height:'swing'},complete:function(){$("#menulevel_innerbox > div").css({display:'none'});$('#menulevel_innerbox').css({marginLeft:'0px'});$('#menuevent_second').css({display:'none'});$('#menuevent_first').css({display:'block'}); $('.menuevents').css({left:'',top:''});$(id).css({display:'block'});}});
$("#menulevel_container").animate({height:'250',opacity:'1'},{duration:'200',specialEasing:{height:'swing'}});
}
});

var iconi=0;
$(".icon_outer").each(function(index){
$(this).css({'left':iconi});
//this.style.left = this.style.left + iconi + "px";
iconi+=73;
});
/*
$("img.icon").mouseover(function(e){

	$(this).animate({width:'80',height:'80'},50);

});

var iid=0;

$("img.icon").click(function(){
if(iid!=$(this).attr("id"))
{
$(this).animate({opacity:'0.3'},30);
$("#"+iid).animate({opacity:'1.0'},30);
	iid=$(this).attr("id");
$("#menulevel_container").animate({height:'250',opacity:'1'},{duration:'200',specialEasing:{height:'swing'}});
}
else
{
	$(this).animate({opacity:'1.0'},30);
	$("#menulevel_container").animate({height:'0',opacity:'0'},{duration:'200',specialEasing:{height:'swing'}});
	iid=0;
}
});
*/
$("img.icon").mouseout(function(e){

$(this).animate({width:'60',height:'60'},150);

});
/*
var iconi=0;
$(".icon_outer").each(function(index){

this.style.left = this.style.left + iconi + "px";
iconi+=84;
});
*/
// $('#pragyan_loginform > fieldset > table').css({'display':'none'});
var ulength=$("#updates > div").size()-3;
var scroll_l = $('#updates').width()/2 - (ulength*10)/2;

$('#updates_scroll').css({'margin-left':scroll_l});
for(var i=0;i<ulength;i++)
{
    if(i!=0)
    {
	$("#updates_scroll").append("<div id=b"+i+" class='update_scroll_but' value="+i+"></div>");
	$("#"+i).css({'display':'none'});
    }
  else
    {
        $("#updates_scroll").append("<div id=b"+i+" class='update_scroll_but' value="+i+"></div>");	
        update();
	}
}

//document.getElementById('updates_inner').style.right = (parseInt($('#updates_scroll').css('width'))+2)+'px';
    var j=$("#updates_inner").width();

	
    var pos=0;
    var time;

    function update()
    {
		
	  if(pos!=0)
		  $("#updates_scroll > #b"+(pos-1)).css({"background-position":"left top"});
	  else
	      $("#updates_scroll > #b"+(ulength-1)).css({"background-position":"left top"});	
		  
	time=setInterval(function s(){
      $("#updates_scroll > #b"+pos).css({"background-position":"left bottom"});
	     $("#updates_inner").width(j);
             j=j-5; 
       
	if(j<0)
       {
            clearInterval(time);
           j=480;
           pos++;
           if(pos==ulength)
           { pos=0;
             $("#updates_inner").width(480);
             $("#"+(ulength-1)).css({'display':'none'});
             $("#0").css({'display':'block'});
             update();
           }
           if(pos<ulength && pos>0)
	   {
            $("#updates_inner").width(480);
            $("#"+(pos-1)).css({'display':'none'});
            $("#"+pos).css({'display':'block'});
            update();
	   }
       }
   },45);
    }

    $(".update_scroll_but").click(function(){
        var d =$(this).attr("value");
		  $("#updates_scroll > #b"+pos).css({"background-position":"left top"});
        if(pos!=d)
	{
        clearInterval(time);
        $("#updates_inner").width(480);
        $("#"+pos).css({'display':'none'});
        $("#"+d).css({'display':'block'});
        pos=d;
        j=480;
        update();
        }        
    });
	
	var k=1;
	var blength=$("#bannerdiv > div").size();
	function banner1()
	{
	if(k>blength)
		k=1;
	$("#ban"+k).fadeIn(1400,function(){$("#ban"+k).fadeOut(1000,function (){k++;banner1();});});
	
	}
	banner1();
	
	/*
setInterval(function()
{
	if(k>blength)
		k=1;
	
	$("#ban"+k).fadeIn(1000);
	$("#ban"+k).fadeOut(1000);
	k++;

},2000);
*/

var sponsor;
var spsrc;
var spdiv;
var sponinfo=$('.sponsor').size();
var l=1;
var prev;
function setsponsor(){
sponsor=setInterval(function(){
	prev = l-1;
		if(l>sponinfo){
			l=1;prev=sponinfo;}

	spdiv = document.getElementById("spr"+l);
	spdiv.style.display="block";
	if(prev){
	spdiv = document.getElementById("spr"+prev);
	spdiv.style.display="none";}
	l++;
	},1700);
}	

var flag=0;

$('#sponsordiv').mouseover(function(){

		clearInterval(sponsor);
		flag=0;
		//$("#sponsordiv").html("<div class='sponsor' style='opacity:0.2'><center><img class='sponsor' style='float:left;' src='images/sponsor/"+(l-1)+".jpg'></center></div><div class='sponsor'>"+sponinfo[l-2]+"</div>");




});
$('#sponsordiv').mouseout(function(e){
		flag=1;
		setsponsor();
});
setsponsor();
});
$(function(){
     $("ul.thumb li").hover(function() {
	$(this).css({'z-index' : '10'});  
	$(this).find('img').addClass("hover").stop() 
		.animate({
			marginTop: '-100px',  
			marginLeft: '-100px',
			top: '50%',
			left: '50%',
			width: '177px', 
			height: '177px', 
			padding: '16px',
			paddingTop: '15px'
		}, 180); 
   $(this).find('div').addClass("hover").stop()
		  .animate({
              opacity:'1',
			  width:'177px',
			  top:'80%',
			  left:'49%'
		  },500);
	} , function() {
		 $(this).find('div').removeClass("hover").stop().css({"opacity":"0","width":"100px","top":"20%","left":"40%"});
	$(this).css({'z-index' : '0'}); 
	$(this).find('img').removeClass("hover").stop() 
		.animate({
			marginTop: '0',
			marginLeft: '0',
			top: '0',
			left: '0',
			width: '100px', 
			height: '100px', 
			padding: '5px'
		}, 400);
});

});
$(function(){

var ani1=1;
setInterval(function(){
if(ani1==1){
$('#ani1_').animate({'opacity':'0.4'},2000);
}
else{
$('#ani1_').animate({'opacity':'1.0'},2000);
}
ani1*=-1;
},1000);

var ani2=1;
setInterval(function(){
if(ani2==1){
$('#ani2_').animate({'opacity':'0.4'},900);
}
else{
$('#ani2_').animate({'opacity':'1.0'},900);
}
ani2*=-1;
},1400);

var ani3=1;
setInterval(function(){
if(ani3==1){
$('#ani3_').animate({'opacity':'0.4'},1100);
}
else{
$('#ani3_').animate({'opacity':'1.0'},1100);
}
ani3*=-1;
},900);


var ani4=1;
setInterval(function(){
if(ani4==1){
$('#ani4_').animate({'opacity':'0.4'},500);
}
else{
$('#ani4_').animate({'opacity':'1.0'},500);
}
ani4*=-1;
},1200);

var ani5=1;
setInterval(function(){
if(ani5==1){
$('#ani5_').animate({'opacity':'0.4'},1000);
}
else{
$('#ani5_').animate({'opacity':'1.0'},1000);
}
ani5*=-1;
},800);

var ani6=1;
setInterval(function(){
if(ani6==1){
$('#ani6_').animate({'opacity':'0.4'},800);
}
else{
$('#ani6_').animate({'opacity':'1.0'},800);
}
ani6*=-1;
},1200);

var ani7=1;
setInterval(function(){
if(ani7==1){
$('#ani7_').animate({'opacity':'0.4'},1800);
}
else{
$('#ani7_').animate({'opacity':'1.0'},1800);
}
ani7*=-1;
},700);

var ani8=1;
setInterval(function(){
if(ani8==1){
$('#ani8_').animate({'opacity':'0.4'},1200);
}
else{
$('#ani8_').animate({'opacity':'1.0'},1200);
}
ani8*=-1;
},500);
$('.aniimg').css({'opacity':'0'});
$('.aniimg').mouseover(function(){
$(this).stop().animate({'opacity':'0.9'},500);
});
$('.aniimg').mouseout(function(){
$(this).stop().animate({'opacity':'0'},500);
});
});

