﻿/// <reference path="jQuery-1.4.1-vsdoc.js" />

var divFadeSpeed = 750;
var nonHoverVis = 500; 
var showDelay = 500;
var bgFadeSpeed = 2000;
var scrollSpeed = 1500;
var twitterScrollSpeed = 8000;

$(document).ready(function(){ 

    checkBrowser();        
    
         
    setUpBG();
       
    
    $("div.bg").fadeIn(1000);
    
       // startSlideshow();
       
    showHideDiv();
    
    $(window).load(function(){
        
        var twitter_timer = setInterval(function(){
                rotateTwitterFeed();
            }, twitterScrollSpeed); 
        
        $("#twtr-widget-1").hover(function(){
            clearInterval(twitter_timer);
            },function(){
                twitter_timer = setInterval(function(){
                rotateTwitterFeed();
            }, twitterScrollSpeed); 
            
            });
        
        $(".twtr-join-conv").text("Follow Me");        
    }); 
    
    //navHover();      
});
  
var doAnimate = true;  
var delay = 2500;


function checkBrowser(){
    if($.browser.msie && parseInt($.browser.version,10) < 8.0){
        $("#dnn_navPane").after("<div id='ieMsg'>Website is best viewed in Internet Explorer Version 8.0 and up.<br /> It may not display properly in your browser. </div>");
    }
}

function rotateTwitterFeed(){

   if($(".twtr-tweets").length != 0){        
        var first = $(".twtr-tweet").first();
        var last = $(".twtr-tweet").last();         
        
        last.prependTo(last.parent())
        last.css("margin-top", -last.height());
        last.animate({marginTop: 0}, 1000);
                
        //last.prependTo(last.parent()).hide().slideDown(1000);  
   }
}

function setUpBG(){
$(window).load(function(){
    

    $("div.bg img").css({opacity:0.0});
    
    var first = "#" + $("div.bg img:first").attr("id");   
    
    
        $(first).css({left : ($(window).width() - $(first).width()) / 2});
    
        $(first).css({opacity: 1.0});
    
        setInterval(function(){    
            changeBG(bgFadeSpeed)
        }, 10000);
    });
}

function changeBG(bgFadeSpeed){        
       var current = $("div.bg img.show") ? $("div.bg img.show") : $("div.bg img:first");
             
       if(current.length == 0){
            current = $("div.bg img:first");
       }
       
       //console.log("current: " + current.attr("id") + " " + current.width());
       
      var next = ((current.next().length) ? ((current.next().hasClass("show")) ? $("div.bg img:first") : current.next()) : $("div.bg img:first"));
      
      //console.log("next: " + next.attr("id"));
      
      next.css({left : ($(window).width() - $("#"+next.attr("id")).width()) / 2});
      next.css({opacity : 0.0}).addClass("show").animate({opacity : 1.0}, bgFadeSpeed);
      //console.log($(window).width());
      current.animate({opacity: 0.0}, bgFadeSpeed).removeClass("show");    
}     
var timeout = null;    
        
function showHideDiv(){
    $(".showhideChild").each(function(){
        var timer;
        var timer2;
  
        $(this).parent().eq(0).hover(function(){              
            if(timer){
                clearTimeout(timer);
                timer = null;
            }            
            
            if(timer2){ 
                clearTimeout(timer2);
                timer2 = null; 
            }
             
            var curId= $(".showhideChild:eq(0)", this).attr("id");            
            
            if(!$("#"+curId).is(":visible")){
                timer = setTimeout(function(){                                           
                    showDiv(curId);  
                }, showDelay);   
            }              
        },
        function(){
            if(timer){
                clearTimeout(timer);
                timer = null;
            } 
            
             if(timer2){
                clearTimeout(timer2);
                timer2 = null;
            }
            
             var curId= $(".showhideChild:eq(0)", this).attr("id");
            timer2 = setTimeout(function(){
            if($("#"+curId).is(":visible")){
                $("#"+curId).css("position", "absolute");
                $("#"+curId).stop().hide("blind", divFadeSpeed); 
                } 
               }, 500);    
        });
    });
    
    /*$(".showhideChild").hover(function(){
        console.log("child hover on");
        if(timer){
                clearTimeout(timer);
                timer = null;
            }
    },function(){
         console.log("child hover off");
    });*/
    
       $(".showhideChildVert").each(function(){
        var timer;
    
        $(this).parent().eq(0).hover(function(){
            if(timer){
                clearTimeout(timer);
                timer = null;
            }            
            
            var curId= $(".showhideChildVert:eq(0)", this).attr("id");
            // console.log(curId);
            timer = setTimeout(function(){                            
                showDiv(curId);  
            }, showDelay);                  
        },
        function(){
             if(timer){
                clearTimeout(timer);
                timer = null;
            }
            //if($(".showhideChild:eq(0)", this).css("display") != "none")
                $(".showhideChildVert:eq(0)", this).hide("slide", {direction: dir}, divFadeSpeed);
        });
    });        
}   


function showDiv(curId){       
    var cur = "#" + curId;    
    
    if($(cur).hasClass("showhideChild")){       
       showHor(cur);   
    }  
    else 
        if($(cur).hasClass("showhideChildVert")){         
            showVert(cur);
        }      
} 

function showHor(cur){
    var leftOffSet;
    var topOffSet;
    
    var parent = $(cur).parent();    
    
    leftOffSet = -parent.position().left + 40;   
    topOffSet =  parent.position().top + parent.height();     
    
    if ( $.browser.msie ){
        topOffSet = topOffSet -5;
    }    
    
    //console.log(topOffSet + " " + leftOffSet);
    $(cur).css("left", leftOffSet);
    $(cur).css("top", topOffSet);  
    $(cur).css("position", "absolute");     
            
    $(cur).stop().show("blind",  divFadeSpeed);
}

var dir = "'left'";

function showVert(cur){
    var leftOffSet;
    var topOffSet;    
    
    var parent = $(cur).parent(); 
    
    leftOffSet =  parent.width();
    topOffSet =  parent.position().top + parseInt(parent.css("margin-top").replace("px",""));    
    
    if($(cur).hasClass("dirRight")){        
        dir = "right";        
        leftOffSet = -$(cur).width();
    }       
    else{
        dir = "left";
    }
    
    //console.log(parent.position().left+" "  + parseInt(parent.css("margin-left").replace("px",""))+ " " + parent.width()+ " "+ leftOffSet);
    
    $(cur).css("left", leftOffSet);
    //$(cur).offset({top:topOffSet, left:leftOffSet});   
    //console.log($(cur).css("left"));
    $(cur).css("top", topOffSet);       
            
            //console.log(dir);
    $(cur).show("slide", {direction: dir}, divFadeSpeed);
}

function startSlideshow(){
    $("#coin-slider").coinslider({        
       	width: 455, // width of slider panel
	    height: 153, // height of slider panel
	    spw: 1, // squares per width
	    sph: 1, // squares per height
	    delay: 3000, // delay between images in ms
	    sDelay: 500, // delay beetwen squares in ms
	    opacity: 0.7, // opacity of title and navigation
	    titleSpeed: 500, // speed of title appereance in ms
	    effect: 'straight', // random, swirl, rain, straight
	    navigation: false, // prev next and buttons
	    links : true, // show images as links
	    hoverPause: true // pause on hover
    });   
}




function navHover(){
    //var shadow_width = $(".nav-shadow").width();
    //var margin = parseInt($(".nav-shadow").css("margin-left").replace("px",""));
    
    $(".nav-icon").hover(function(){
        $(this).stop().animate({ marginTop: "-14px" }, 250, function() {
		    	$(this).animate({ marginTop: "-10px" }, 250);
		    	//$(this).parents(".nav_img").find(".nav_icon_text").show("shake", {times:1, distance:3, direction:"up"}, 150);
		    });
        //$(this).parents(".nav_img").find(".nav-shadow").stop().animate({ width: shadow_width*0.8+"px", marginLeft: (margin+5) + "px", height:"41px", opacity: 0.25 }, 250);   
             
    },function(){
        $(this).stop().animate({ marginTop: "4px" }, 250, function() {
		    	$(this).animate({ marginTop: "0px" }, 250);
		    });
		// $(".nav-shadow").stop().animate({ width: shadow_width+"px", marginLeft: (margin) + "px", opacity: 1 }, 250);
    });

}



