$(document).ready(function(){
	
//Navigation
	$('#menu a').click( function () {
	$('#menu a').removeClass("active");
	$(this).addClass("active");
	}); 

	$('#logo').click( function () {
	$('#menu a').removeClass("active");
	}); 
	
//START: Added by Hizam 1-12-2011

$("#login-link").click(function(){
    $("#login-panel").slideToggle(200);
});

$(document).keydown(function(e) {
    if (e.keyCode == 27) {
        $("#login-panel").hide(0);
    }
});


$("#tip4").click(function() {
	$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'			: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

	return false;
});

//END: Added by Hizam 1-12-2011

	
//Portfolio Image Hover
$(".recent-work li, .portfolio li").hover(function () {						 
	$(this).find("img").stop(true, true).animate({ opacity: 0.5 }, 500);
	$(this).find(".view-image, .view-video").fadeIn(500);
}, function() {
	$(this).find("img").stop(true, true).animate({ opacity: 1.0 }, 300);
	$(this).find(".view-image, .view-video").fadeOut(300);
});


//Initializate fancybox
$("a[data-id^='fancybox']").fancybox({
				'overlayShow'	: true,
				'overlayColor'		: '#000',
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'				
}); 

$("a[data-id^='fancybox-portfolio']").fancybox({
				'overlayShow'	: true,
				'overlayColor'		: '#000',
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic',
				'height' : 800,
				'width'	: 800		
}); 


//Scrol
$('#menu a, #logo, .scrol').click(function() {
	var elementClicked = $(this).attr("href");
	var destination = $(elementClicked).offset().top;
	$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-0}, 1000 );		   
	return false;
});	
		
});


$(window).load(function() {
        //Image Hover Efect
		$(".loading").fadeOut(1000); 	
});


$(function () {
    $('.error').hide();
    $('input.text-input').css({
        backgroundColor: "#FFFFFF"
    });
    $('input.text-input').focus(function () {
        $(this).css({
            backgroundColor: "#FFDDAA"
        });
    });
    $('input.text-input').blur(function () {
        $(this).css({
            backgroundColor: "#FFFFFF"
        });
    });

    $('textarea.text-input').css({
        backgroundColor: "#FFFFFF"
    });
    $('textarea.text-input').focus(function () {
        $(this).css({
            backgroundColor: "#FFDDAA"
        });
    });
    $('textarea.text-input').blur(function () {
        $(this).css({
            backgroundColor: "#FFFFFF"
        });
    });

    $("#submit_btn").click(function () {
        // validate and process form
        // first hide any error messages
        $('.error').hide();

        var name = $("input#name").val();
        if (name == "") {
            $("label#name_error").show();
            $("input#name").focus();
            return false;
        }
        var email = $("input#email").val();
        if (email == "") {
            $("label#email_error").show();
            $("input#email").focus();
            return false;
        }
        var subj = $("input#subj").val();
        if (subj == "") {
            $("label#subj_error").show();
            $("input#subj").focus();
            return false;
        }

        var masej = $("textarea#masej").val();
        if (masej == "") {
            $("label#masej_error").show();
            $("textarea#masej").focus();
            return false;
        }

        var dataString = 'name=' + name + '&email=' + email + '&subj=' + subj + '&masej=' + masej;
        //alert (dataString);return false;
        $.ajax({
            type: "POST",
            url: "mail.php",
            data: dataString,
            success: function () {
                $('#contact_form_message').html("<div id='message'></div>");
                
        		$('#message').html("<h2>Contact Form Submitted!</h2>").append("<p>We will be in touch soon.</p>").hide().fadeIn(1500, function() {
          			$('#message').append("<img id='checkmark' src='images/check.png' />");
                });
            }
        });
        return false;
    });
});
runOnLoad(function () {
    $("input#name").select().focus();
});
