﻿/// <reference path="jquery-1.4.1-vsdoc.js" />

var sizeIncrease = 5;
var sizeIncreaseSpeed = 100;

var twitter_script = "<script type='text/javascript' src='http://twitter.com/javascripts/blogger.js'></script><script type='text/javascript' src='http://twitter.com/statuses/user_timeline/helenesbridals.json?callback=twitterCallback2&count=100'></script>";

var twitterScrollSpeed = 5000;

var catConfig = {
    over: dAOver,
    out: dAOut,
    timeout: 250,
    sensitivity: 7,
    interval: 100
};

$(document).ready(function(){
    $('ul#rotatorUl > li').hide();
    startRotating($('ul#rotatorUl > li:first'));
    
    
     $(window).load(function() {
        $('#slider').nivoSlider({
            effect: 'fade',
            pauseTime: 5000,
            directionNavHide: false,
            controlNav: false
        }); 
        
        $('marquee').marquee().mouseover(function () {
            $(this).trigger('stop');
        }).mouseout(function () {
            $(this).trigger('start');
        }).mousemove(function (event) {
            if ($(this).data('drag') == true) {
            this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
            }
        }).mousedown(function (event) {
            $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
        }).mouseup(function () {
            $(this).data('drag', false);
        });
        
         $("#twitter_content").append(twitter_script);
        
        var twitter_timer = setInterval(function(){
                rotateTwitterFeed();
            }, twitterScrollSpeed); 
        
        $("#twitter_update_list").hover(function(){
            clearInterval(twitter_timer);
            },function(){
                twitter_timer = setInterval(function(){
                rotateTwitterFeed();
            }, twitterScrollSpeed); 
            
            });
            
         touchScroll("testimonials_div");      
    });
    
    toggleSection();    
       
    $("#twitter_content").append(twitter_script);
    openTwitter(); 
    
    $(".cat").hoverIntent(catConfig);
    
    $(".cat_sub").hoverIntent(catConfig);
});

function rotateTwitterFeed(){   
        //var tweet_list = $("#twitter_update_list");
       
        var first =$("#twitter_update_list").children("li").first();
        var last = $("#twitter_update_list").children("li").last();         
        
        //console.log(last);
        
        last.prependTo(last.parent());
        last.css("margin-top", -last.height());
        last.animate({marginTop: 0}, 1000);
                
        //last.prependTo(last.parent()).hide().slideDown(1000);  
   
}


var doAnimate = true;  
var delay = 2500;

function startRotating(content){
   if(doAnimate){   
        $('ul#rotatorUl > li').css('list-style-type', 'none');
   
        content.fadeIn(delay, function(content){
                    
                return function(){   
                    content.delay(delay);             
                    content.fadeOut(delay, function(){
                
                    if($(this).attr("id") == $('ul#rotatorUl > li:last').attr('id')){                                                   
                        startRotating($('ul#rotatorUl > li:first'));                           
                    }
                    else{                       
                        startRotating($(content.next()));                       
                    }
                    });
                };            
        } (content));        
     }     
}

function toggleSection(){
    $(".heading_plus_minus").text("+");
    
    $(".heading").click(function(){
        var con =  $(this).next(".content");
        var pl = con.prev(".heading").children(".heading_plus_minus");
        
        pl.setPlusMinus();  
        con.slideToggle(500);              
        con.closeOtherCnt();                
    });      
}

$.fn.setPlusMinus = function(){ 
    var e = $(this);   
    if(e.text() == "-"){    
        e.text("+");
    }
    else{
    console.log("here");
        e.text("-");
    }
}

 $.fn.closeOtherCnt = function(){
   $(this).siblings(".content").each(function(){
    if($(this).css("display") == "block"){
        $(this).hide(500);
        $(this).prev(".heading").children(".heading_plus_minus").text("+");       
    }
   });
}

function openTwitter(){
    $(".content.twitter").slideToggle(500, function(){
        $(this).prev(".heading.twitter").children(".heading_plus_minus.twitter").text("-");
    });   
}


function dAOver(){
      $(this).dAOverObject();
}

$.fn.dAOverObject = function(){       
        var area = $(this);
        var img = area.find("img");
        var newHeight = img.height() + sizeIncrease;
        var newWidth = Math.floor(img.width() * newHeight / img.height());
        var newLeft = Math.floor((newWidth - img.width()) / 2);      
        
        img.css("z-index", 1);
        img.animate({left: -newLeft, top: -(sizeIncrease/2), height: newHeight+"px"}, sizeIncreaseSpeed);          
}

function dAOut(){
    $(this).dAOutObject();
}

$.fn.dAOutObject = function(){  
        var area = $(this);
        var img = area.find("img");
        var newHeight = img.height() - sizeIncrease;    
       
        img.css("z-index", 0);
        img.animate({left: 0, top: 0, height: newHeight+"px"}, sizeIncreaseSpeed);   
}






