$(document).ready(
function() {

////////////////////////////////////////////////////////////////////////////////
// Bird animation    
    var clicked=new Array();
    clicked['bird1']=0;clicked['bird2']=0;clicked['bird3']=0;clicked['bird4']=0;clicked['bird5']=0;
    $('.bird').mouseover(function() {
        var clk_id = $(this).attr('id');
        clicked[clk_id]++;
        if (clicked[clk_id] == 1) {
            var rnd_left = random_number(-2000, -1500);
            var rnd_top = random_number(-400,-100);
            $(this).sprite({fps: 20, no_of_frames: 6})
                    .spRandom({
                          left: rnd_left,
                          top: rnd_top,
                          bottom:10,
                          right:10,
                          speed: 4000,
                          pause: 3500
                      });
            setTimeout(function(){
                $(clk_id).hide();
            },3000);
        }
    });
            
            
////////////////////////////////////////////////////////////////////////////////
// Rollover li - show/hide li
	var slides, switches;
	slides = $('#slides li');
	switches = $('#switches li');

    slides.each(function(idx) {
            $(this).data('slide', switches.eq(idx));
        }).hover(
        function() {
            switches.removeClass('active');
            slides.removeClass('active');
            $(this).addClass('active');
            $(this).data('slide').addClass('active');
        });


////////////////////////////////////////////////////////////////////////////////
// Rollover li - show/hide div
//	var slides, switches;
//	slides = $('#slides div');
//	switches = $('#switches li');

//    switches.each(function(idx) {
//            $(this).data('slide', slides.eq(idx));
//        }).hover(
//        function() {
//            switches.removeClass('active');
//            slides.removeClass('active');
//            $(this).addClass('active');
//            $(this).data('slide').addClass('active');
//        });
///////////////////////////////////////////////////////////////////////////
// Magic line

    var $el, leftPos, newWidth,
    	$alter = -6,
        $mainNav2 = $("#menu");


    $mainNav2.append("<li id='magic-line'></li>");

    var $magicLineTwo = $("#magic-line");

    $magicLineTwo
        .width(76) // cloud width
        .height(42) // cloud height
        .css("left", $(".current_page_item a").position().left+$alter)
        .data("origLeft", $(".current_page_item a").position().left)
        .data("origWidth", $magicLineTwo.width())
        .data("origColor", $(".current_page_item a").attr("rel"));

    $("#menu li").find("a").hover(function() {
        $el = $(this);
        leftPos = $el.position().left+$alter;
        $magicLineTwo.stop().animate({
            left: leftPos
        })
    }, function() {
        $magicLineTwo.stop().animate({
            left: $magicLineTwo.data("origLeft")+$alter
        });
    });

    // In case of window resize, calculate starting position again
    $(window).resize(function() {
	    $magicLineTwo
	        .width(76) // cloud width
	        .height(42) // cloud height
	        .css("left", $(".current_page_item a").position().left+$alter)
	        .data("origLeft", $(".current_page_item a").position().left)
	        .data("origWidth", $magicLineTwo.width())
	        .data("origColor", $(".current_page_item a").attr("rel"));
	});


///////////////////////////////////////////////////////////////////////////
// Rollover image

	$("img.a").hover(
	function() {
	$(this).stop().animate({"opacity": "0"}, "fast");
	},
	function() {
	$(this).stop().animate({"opacity": "1"}, "slow");
	});


///////////////////////////////////////////////////////////////////////////
// Scroll div with screen

	var $scrolling_div = $("#cont_text_left");
	var $height_limit = $("#cont_text").height();
	var $header_height = $("#header").height()+40; // 50 is margin-bottom
	var padd_bottom = 80; // 90 is padding-bottom

	$(window).scroll(function(){
		$active_height = $('#switches li:visible').height();
		//alert($('#switches li.active').height());
		if (($(window).scrollTop() >= $header_height) && ($(window).scrollTop() <= $height_limit)) {
			$max_top = $height_limit - $active_height + padd_bottom;
			$calc_top = $(window).scrollTop() - $header_height;
			if ($calc_top > $max_top) {
				$calc_top = $max_top;
			}
    		$scrolling_div
    			.stop()
	            .animate({"marginTop": ($calc_top) + "px"}, "fast" );
		} else if ($(window).scrollTop() > $height_limit) {
			$scrolling_div
    			.stop()
    			.animate({"marginTop": ($height_limit - $active_height + padd_bottom) + "px"}, "fast" );
		} else {
    		$scrolling_div
    			.stop()
	            .animate({"marginTop": "0px"}, "fast" );
		}
		/*$('#switches li:visible h4').text($height_limit+": "+$(window).scrollTop()+" - "+$active_height);*/
	});


///////////////////////////////////////////////////////////////////////////
// Languange change
	$('#lang_select').change(function() {
		$(this).closest("form").submit();
	});

 });

 //function to get random number
function random_number(min,max,float_val)
{
	var random_value = min+(Math.random()*(max-min));
	return typeof float_val=='undefined'?Math.round(random_value):random_value.toFixed(float_val);
}
