/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * 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;
    }
};
//visual effects for the navigation
function mainnavi(){
	//Add the rounded corners to each dropdown
	$('li ul').each(function(index) {
		$(this).find('li:first').css({'border-top':'none'});
		$(this).append('<li class="dropdown_bottom"></li>').prepend('<li class="dropdown_top"></li>')
	});
	//If browser isn't IE then applay a fade effect on hover
	if(!($.browser.msie)){
		$("#navigation ul").css({"display":"none", "opacity": 0});

		$("#navigation li").hover(function(){
			$(this).find('ul:first').css({'display':"block"}).stop().animate({'opacity':1},100);
		},function(){
			$(this).find('ul:first').stop().animate({'opacity':0},250,function(){
				$(this).css({'display':"none"});
			});
		});
	}
}
/*If the window size is below 960px set the width of all ellements with width 100% to 960px*/
function stretch(){
	var viewportWidth = $(window).width();
	if(viewportWidth < 960){
		$('#top_wrapper_line_t, #top_wrapper_line_b, #footer_very_bottom_wrapper, #footer_wrapper_line').css({width:960});
	}else{
		$('#top_wrapper_line_t, #top_wrapper_line_b, #footer_very_bottom_wrapper, #footer_wrapper_line').css({width:'100%'});
	}
	window.onresize = stretch;
}
function validate_contactform(){

	$('.contactform').append('<div id="c_loader"></div>');
	$('#c_submit').hide();
	
	var c_name = $('#c_name'), c_email = $('#c_email'), c_website = $('#c_website'), c_subject = $('#c_subject'), c_message = $('#c_message');
	var filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	var error_exist = 0;
	
	
	if(c_name.val().length < 4){
		c_name.addClass('error');
		error_exist++;
	}else{
		c_name.removeClass('error');
	}	
	if(c_subject.val().length < 4){
		c_subject.addClass('error');
		error_exist++;
	}else{
		c_subject.removeClass('error');
	}
	if(c_website.val().length > 0){
		if(c_website.val().length < 4){
			c_website.addClass('error');
			error_exist++;
		}else{
			c_website.removeClass('error');
		}
	}else{
		c_website.removeClass('error');
	}	
	if(c_message.val().length < 10){
		c_message.addClass('error');
		error_exist++;
	}else{
		c_message.removeClass('error');
	}	
	if(!filter.test(c_email.val())){
		c_email.addClass('error');
		error_exist++;
	}else{
		c_email.removeClass('error');
	}
	
	if(error_exist > 0){
		$('#c_loader').remove();
		$('#c_submit').show();

	}else{
		var dataString = 'name='+ c_name.val() + '&subject='+ c_subject.val() + '&email=' + c_email.val() + '&website=' + c_website.val() + '&message=' + c_message.val();
		$.ajax({
			type: "POST",
			url: "sendmail.php",
			data: dataString,
			success: function(response) {
				if(response == "sent"){
					$('#c_loader').remove();
					$('.contactform').prepend('<div class="noti_success">Message has been sent successfull! We will get in contact with you shortly</div>');
				}else{
					$('#c_loader').remove();
					$('#c_submit').show();
					$('.contactform').prepend('<div class="noti_error">There was an error while sending your message</div>');
				}
			}
		});
	}
	
}
function validate_footercontactform(){
	
	var fc_name = $('#fc_name'), fc_email = $('#fc_email'), fc_message = $('#footer_textarea');
	var filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	var error_exist = 0;
	
	
	if(fc_name.val().length < 4 || fc_name.val() == "name"){
		fc_name.addClass('error');
		error_exist++;
	}else{
		fc_name.removeClass('error');
	}	
	if(fc_message.val().length < 10 || fc_message.val() == "Your Message"){
		fc_message.addClass('error');
		error_exist++;
	}else{
		fc_message.removeClass('error');
	}	
	if(!filter.test(fc_email.val())){
		fc_email.addClass('error');
		error_exist++;
	}else{
		fc_email.removeClass('error');
	}
	
	if(error_exist > 0){
	}else{
		var dataString = 'name='+ fc_name.val() + '&email=' + fc_email.val() + '&message=' + fc_message.val();
		$.ajax({
			type: "POST",
			url: "sendmail_footer.php",
			data: dataString,
			success: function(response) {
				if(response == "sent"){
				
				}else{
				
				}
			}
		});
	}
	
}
$(document).ready(function(){
	mainnavi();
	stretch();
	$('#c_submit').click(function(){
		validate_contactform();
		return false;
	});
	$('#footer_submit').click(function(){
		validate_footercontactform();
		return false;
	});
	
	/*$('h1, h3').click(function(){
		$('#colorsheme').attr('href', 'styles/darkwood.css')
	});*/
	
	
});
