

// Menu dropdown 
$(document).ready(function(){
	$('#top-menu li').hover(function(){
		 $(this).find('ul.sub-menu').hide().slideDown(200);
		}, function(){
			$(this).find('ul.sub-menu').hide();
		});	
});

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


//Switch Style 
$(document).ready(function(){
	//Set default color scheme
	var defcolor = 'green';
	$("#stylecolor").attr('href', 'css/'+defcolor+'.css');
	
	if($.cookie("color")) {
		$("#stylecolor").attr('href', $.cookie("color"));
	}
	$('#skin li a').click(function(e){
		e.preventDefault();
		var picked = $(this).attr('class');
			$("#stylecolor").attr('href', 'css/'+picked+'.css');
			// Set Cookie 
			$.cookie("color", 'css/'+picked+'.css');
				// Current Selection
				var curColor = $("#stylecolor").attr('href').split('/')[1].split('.')[0];
				$('#skin li a').removeClass('sel');
				$('#skin li a.'+curColor+'').addClass('sel');	
	});
	var curColor = $("#stylecolor").attr('href').split('/')[1].split('.')[0];
	$('#skin li a.'+curColor+'').addClass('sel');	
});

//Portfolio maginifire
$(document).ready(function(){
	$('#gallery li a').prepend('<span class="magni" />');
	$('.magni').css('opacity', 0);
	$('#gallery li a').hover(function(){
			$(this).find('.magni').stop().animate({'opacity': 1});
		}, function(){
			$(this).find('.magni').stop().animate({'opacity': 0});	
		});
});

//Form Processing
$(document).ready(function(){
	$('#form-contact').submit(function(e){
		e.preventDefault();
		// Get Variables
		var name = $('#name').val();
		var email = $('#email').val();
		var subj = $('#subject').val();
		var message = $('#message').val();
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var working = true;
		var loader = '<img src="img/loader.gif" alt="working..." id="loader" />';
		// Validate Name
			if(name === 'Name' || email === 'Email' || subj === 'Subject' || message === 'Your Message') {
				$('#resp').html('<span class="error">All Fields are required with a valid email id</span>');
			}else{
				//Ajax submit
				$('#resp').html(loader);
				$.ajax({
   					type: "POST",
   					url: "sendmail.php",
   					data: $('#form-contact').serialize(),
   					success: function(data){
						if(data === '0') {
							//Error
							$('#resp').html('<span class="error">All Fields are required with a valid email id</span>');
						}else{
							// Mail sent successfully
							$('#resp').html('<span style="color:green; font-size:16px"> Mail sent successfully !</span>');
								//Reset form
								$('#name').val('Name');
								$('#email').val('Email');
								$('#subject').val('Subject');
								$('#message').val('Your Message');
						}
   					}
 			});
		}
	});
});

