jQuery('document').ready(function(){

	jQuery("ul.links li").hover(
		function () {
			jQuery(this).addClass('hover');
		}, 
		function () {
			jQuery(this).removeClass('hover');
		}
	);
	

    jQuery('.box-collateral-swicher2 .tab2 a').click(function(e) {
        e.preventDefault();
        jQuery('.box-collateral-swicher2 .tab1').removeClass('active');
        jQuery('.box-collateral-holder-additional').css('display','none');            
        
        jQuery('.box-collateral-swicher2 .tab2').addClass('active');    
        jQuery('.box-collateral-holder-description').css('display','inline');            
    });    
    
    jQuery('.box-collateral-swicher2 .tab1 a').click(function(e) {
        e.preventDefault();
        jQuery('.box-collateral-swicher2 .tab2').removeClass('active');
        jQuery('.box-collateral-holder-description').css('display','none');            
        
        jQuery('.box-collateral-swicher2 .tab1').addClass('active');    
        jQuery('.box-collateral-holder-additional').css('display','inline');            
    });        

});


/* google maps - starts */

function showMap() {

  var myOptions = {
    zoom: 14,
    center: new google.maps.LatLng(55.692911,21.196446),
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    scrollwheel: false
  }
  var map = new google.maps.Map(document.getElementById("map"), myOptions);

  setMarkers(map, offices);

}


var offices = [
  ['Laivo sandelis', 55.692911,21.196446, 1]
]

function setMarkers(map, locations) {
  var image = new google.maps.MarkerImage('/skin/frontend/laivosandelis/default/images/icon.png',
      // This marker is 20 pixels wide by 32 pixels tall.
      new google.maps.Size(68, 66),
      // The origin for this image is 0,0.
      new google.maps.Point(0,0),
      // The anchor for this image is the base of the flagpole at 0,32.
      new google.maps.Point(31, 66));

  for (var i = 0; i < locations.length; i++) {
    var office = locations[i];
    var myLatLng = new google.maps.LatLng(office[1], office[2]);
    var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        icon: image,
        title: office[0],
        zIndex: office[3]
    });
  }
}

jQuery('document').ready(function(){
    if(jQuery('#map').length > 0){
        showMap();
    }
});


/* google maps - ends */


function startBannerCarousel(){
    pendingAnimation = false;
    bannerTimer = null;
    activeBanner = 0;
    bannerCount = jQuery("#bannerCarousel img").length;
    if (bannerCount > 1) {
        bannerTimer = setInterval("rotateBannerCarousel()", 5000);
        jQuery("#bannerCarousel img").hover(
            function () {
                stopBannerCarousel();
            }, 
            function () {
                bannerTimer = setInterval("rotateBannerCarousel()", 5000);
            }
        );

// NEW SCHOOL

        jQuery('#bannerCarousel .new-navigation-back a').live('click', function(e){
            e.preventDefault();
            if (pendingAnimation) {
                return false;
            }
            stopBannerCarousel();
            var i = activeBanner - 1;
            if (i < 0) {
                i = bannerCount - 1;
            }
            skipBannerCarousel(i);
            bannerTimer = setInterval("rotateBannerCarousel()", 5000);
        });

        jQuery('#bannerCarousel .new-navigation-next a').live('click', function(e){
            e.preventDefault();
            if (pendingAnimation) {
                return false;
            }
            stopBannerCarousel();
            var i = activeBanner + 1;
            if (i >= bannerCount) {
                i = 0;
            }
            skipBannerCarousel(i);
            bannerTimer = setInterval("rotateBannerCarousel()", 5000);
        });

// NEW SCHOOL END

// OLD SCHOOL

        jQuery("#bannerCarousel ul li a").live('click', function(e){
            e.preventDefault();
            if (pendingAnimation) {
                return false;
            }
            stopBannerCarousel();
            skipBannerCarousel(jQuery("#bannerCarousel ul li a").index(this));
            bannerTimer = setInterval("rotateBannerCarousel()", 5000);
        });

// OLD SCHOOL END

    }
}

function stopBannerCarousel(){
    if (bannerTimer === null) {
        return;
    }
    clearInterval(bannerTimer);
}

function rotateBannerCarousel(){
    pendingAnimation = true;
    jQuery("#bannerCarousel img:eq(" + activeBanner + ")").hide();
    jQuery("#bannerCarousel ul li:eq(" + activeBanner + ")").removeClass("active");
    activeBanner++;
    if (activeBanner >= bannerCount) {
        activeBanner = 0;
    }
    jQuery("#bannerCarousel img:eq(" + activeBanner + ")").show();
    jQuery("#bannerCarousel ul li:eq(" + activeBanner + ")").addClass("active");

// NEW SCHOOL

    navName.text(jQuery('#bannerCarousel a:eq(' + activeBanner + ')').attr('title'));
    navText.text((activeBanner + 1) + '/' + bl);

// NEW SCHOOL END

    pendingAnimation = false;
}

function skipBannerCarousel(i){
    pendingAnimation = true;
    jQuery("#bannerCarousel img:eq(" + activeBanner + ")").hide();
    jQuery("#bannerCarousel ul li:eq(" + activeBanner + ")").removeClass("active");
    activeBanner = i;
    jQuery("#bannerCarousel img:eq(" + activeBanner + ")").show();
    jQuery("#bannerCarousel ul li:eq(" + activeBanner + ")").addClass("active");

// NEW SCHOOL

    navName.text(jQuery('#bannerCarousel a:eq(' + activeBanner + ')').attr('title'));
    navText.text((activeBanner + 1) + '/' + bl);

// NEW SCHOOL END
    pendingAnimation = false;
}

jQuery(function(){
    jQuery("#bannerCarousel img:first").show();
    bl = jQuery("#bannerCarousel img").length;
    if (bl > 1) {

// NEW SCOOL

        navigation = jQuery('<div />').addClass('new-navigation').appendTo('#bannerCarousel');
        navName = jQuery('<div />').addClass('new-navigation-name').appendTo(navigation);
        navBack = jQuery('<div />').addClass('new-navigation-back').appendTo(navigation);
        navText = jQuery('<div />').addClass('new-navigation-text').appendTo(navigation);
        navNext = jQuery('<div />').addClass('new-navigation-next').appendTo(navigation);

        navBacklink = jQuery('<a />').attr({href: "#", title: ""}).appendTo(navBack);
        navBacklink.click(function(e){
            e.preventDefault();
        });

        navNextlink = jQuery('<a />').attr({href: "#", title: ""}).appendTo(navNext);
        navNextlink.click(function(e){
            e.preventDefault();
        });

        navName.text(jQuery('#bannerCarousel a:first').attr('title'));

        navText.text('1/' + bl);

// NEW SCHOOL END
// OLD SCHOOL

        var ul = jQuery('<ul />').appendTo("#bannerCarousel");

        for(i=0; i<bl; i++) {
            var li = jQuery('<li />').appendTo(ul);

            var a = jQuery('<a />').attr({
                href:  "#",
                title: ""
            }).appendTo(li);
            a.click(function(e){
                e.preventDefault();
            });
        }

        jQuery("#bannerCarousel ul li:first").addClass('active');

// OLD SCHOOL END

        startBannerCarousel();
    }
});


