/*
 * Copyright (c) 2009 Dotanimizers (service@dotanimizers.com)
 * Application js
 */
jQuery(function() {



		var v = jQuery("#form2").validate({
                        errorPlacement: function(error, element) {
				error.appendTo( element.parent("input").next("input") );
			},
			submitHandler: function(form) {
				jQuery(form).ajaxSubmit({
					target: "#messageSent"
				});
                                $(".error").hide();
                                closeForm();
                                v.resetForm();
			}
		});


		$("#accordion").accordion({

                        autoHeight: false

		});

	});

$.fn.wait = function(time, type) {
    time = time || 720;
    type = type || "fx";
    return this.queue(type, function() {
        var self = this;
        setTimeout(function() {
            $(self).dequeue();
        }, time);
    });
};

function showForm() {
$("#contactForm").slideDown("slow");
    $("div.contactusbg").hide("slow");
    $(".concursor").hide("fast");
    $(".concursor2").show("fast");
    $("#id1").wait().show("slow");
    $(".textright").wait().show("slow");
    $(".menu").wait().fadeOut("slow");
    $("#linkshr").wait().fadeOut("slow");
}

function hideForm(){
    $("#contactForm").slideUp("slow");
    $("div.contactusbg").show("slow");
    $(".concursor2").hide("slow");
    $(".concursor").show("slow");
    $("#id1").hide("slow");
    $(".textright").hide("slow");
    $(".menu").wait().fadeIn("slow");
    $("#linkshr").wait().fadeIn("slow");
}


function closeForm(){
    $("#messageSent").show("slow");
    setTimeout('$("#messageSent").hide();hideForm();', 2000);
    $("div.contactusbg").show("slow");
}



        $(document).ready(function(){

            $("#contactLink").click(
                function(){
                    if ($("#contactForm").is(":hidden") && $("div.contactusbg").is(":visible") ){
                    showForm();
                    }
                    else{
                    hideForm();
                    }
                }
            );

            $(".contactusbg").click(
                function(){
                $(".contactusbg").slideDown('slow');
                $("#div2").slideDown('slow');
                $("#div2").effect("bounce",{ times:6 },160);}
            );

            $("#button").click(function(){
                     $("#div2").slideUp('slow');
                     $("#div2").fadeOut('fast');
            });
            $("#shake").mouseover(function(){
                $("#shake").fadeOut('slow');
                $(this).effect("bounce",{ times:5 },80);
            });
            $("#shake").mouseout(function(){
                $("#shake").fadeIn('slow');

            });


            $("#bottom").click(function(){
                /*alert("Hello world");*/
                $("#middlebody").slideDown(2000);
                $(".midlink2").hide("slow");
                $(".midlink").show("slow");
            });

            /*middle container button*/
           $(".midlink").click(function(){
//               var cssObj = {
//                    'background': 'url("../images/uparrow.png")',
//                    'border' : '3px solid red',
//                    'color' : 'rgb(0,40,244)'
//                  }alert("hello");
                $(".midlink").hide("slow");
                $(".midlink2").show("slow");
                $("#middlebody").slideUp(2000);
                }
            )

            $(".midlink2").click(function(){
//               var cssObj = {
//                    'background': 'url("../images/uparrow.png")',
//                    'border' : '3px solid red',
//                    'color' : 'rgb(0,40,244)'
//                  }alert("hello");


                $(".midlink").show("slow");
                $(".midlink2").hide("slow");
                $("#middlebody").slideDown(2000);
                
                }
            )


/**
 * slider for projects
 *
**/
var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;

$(document).ready(function(){
  headline_count = $("div.headline").size();
  $("div.headline:eq("+current_headline+")").css('top','5px');

  headline_interval = setInterval(headline_rotate,5000); //time in milliseconds
  $('#scrollup').hover(function() {
    clearInterval(headline_interval);
  }, function() {
    headline_interval = setInterval(headline_rotate,5000); //time in milliseconds
    headline_rotate();
  });
});

function headline_rotate() {
  current_headline = (old_headline + 1) % headline_count;
  $("div.headline:eq(" + old_headline + ")").animate({top: -205},"slow", function() {
    $(this).css('top','210px');
    });
  $("div.headline:eq(" + current_headline + ")").show().animate({top: 5},"slow");
  old_headline = current_headline;
}

        });
        








