var $ = jQuery.noConflict();

jQuery(document).ready(function(jQuery) {

	/*-------------------------------------------------*/
	/* =  Dropdown Menu - Superfish
	/*-------------------------------------------------*/
	try {
		jQuery('ul.sf-menu').superfish({
			delay: 400,
			autoArrows: false,
			speed: 'fast',
			animation: {opacity:'show', height:'show'}
		});
	} catch (err){

	}
        /*-------------------------------------------------*/
	/* =  Banner slider
	/*-------------------------------------------------*/

	var sliderBanner = $('#banner .bxslider');
	try{		
		sliderBanner.bxSlider({
			auto: true,
			mode: 'vertical'
		});
	} catch(err) {
		//alert ('There was an issue displaying the slider');
	}
        
        
        // page head lightbox
          try{
		jQuery("a.page-lightbox").fancybox({openEffect  : 'fade',closeEffect : 'fade',prevEffect : 'elastic',nextEffect : 'elastic',closeBtn  : false,helpers : {title : {type : 'inside'},buttons	: {}}});
	} catch(err) {
		
	}
//page hea slider
        jQuery('.flexslider').flexslider();
	/*-------------------------------------------------*/
	/* =  Scroll to TOP
	/*-------------------------------------------------*/

	/*-------------------------------------------------*/
	/* =  Mobile Menu
	/*-------------------------------------------------*/
	// Create the dropdown base
    jQuery("<select />").appendTo("#nav");
    
    // Create default option "Go to..."
    jQuery("<option />", {
		"selected": "selected",
		"value"   : "",
		"text"    : "Go to..."
    }).appendTo("#nav select");
    
    // Populate dropdown with menu items
    jQuery(".sf-menu a").each(function() {
		var el = jQuery(this);
		jQuery("<option />", {
			"value"   : el.attr("href"),
			"text"    : el.text()
		}).appendTo("#nav select");
    });

    jQuery("#nav select").change(function() {
		window.location = jQuery(this).find("option:selected").val();
    });
    
    /* recent works portfolio shortcode*/
    jQuery('.carousel-inner').bxSlider();
	
	/*-------------------------------------------------*/
	/* =  Scroll to TOP
	/*-------------------------------------------------*/
	jQuery('a[href="#top"]').click(function(){
        jQuery('html, body').animate({scrollTop: 0}, 'slow');
        return false;
    });

    	/*-------------------------------------------------*/
	/* =  Input & Textarea Placeholder
	/*-------------------------------------------------*/
	jQuery('input[type="text"], textarea').each(function(){
		jQuery(this).attr({'data-value': jQuery(this).attr('placeholder')});
		jQuery(this).removeAttr('placeholder');
		jQuery(this).attr({'value': jQuery(this).attr('data-value')});
	});

	jQuery('input[type="text"], textarea').focus(function(){
		jQuery(this).removeClass('error');
		if(jQuery(this).val().toLowerCase() === jQuery(this).attr('data-value').toLowerCase()){
			jQuery(this).val('');
		}	
	}).blur( function(){ 
		if(jQuery(this).val() === ''){
			jQuery(this).val(jQuery(this).attr('data-value'));
		}
	});


       /*-------------------------------------------------*/
	/* =  Tabs Widget - { Popular, Recent and Comments }
	/*-------------------------------------------------
	jQuery('.tab-links li a').live('click', function(e){
		e.preventDefault();
		if (!jQuery(this).parent('li').hasClass('active')){
			var link = jQuery(this).attr('href');

			jQuery(this).parents('ul').children('li').removeClass('active');
			jQuery(this).parent().addClass('active');

			jQuery('.tabs-widget > div').hide();

			jQuery(link).fadeIn();
		}
	});
    *//* ---------------------------------------------------------------------- */
	/*	accordion
	/* ---------------------------------------------------------------------- */
		try {
			var tabContent = $(".tabs");
			tabContent.tabs();
		} catch(err) {

		}

		var acordDivHide = $('.accordion div'),
			acordHeadClick = $('.accordion h2');


		acordDivHide.addClass('hide');

		acordHeadClick.on('click', function() {
			var $this = $(this);
			
			if ( !$this.hasClass('active')) {
			acordHeadClick.removeClass('active');
			$this
				.addClass('active')
				.next()
					.slideDown(300)
					.siblings('.accordion div')
						.slideUp(300);
			}
			else {
				$(this).removeClass('active')
						.next()
						.slideUp(300);
			}
		});

	/*-------------------------------------------------*/
        // Toggles
	$(".toggle-container").hide();
	$(".toggle-trigger").click(function(e){
		e.preventDefault();
		$(this).toggleClass("open").next().slideToggle(500);
		return false;
	});
	$(".nav-list.affix").affix();
	$(".alert").alert();

    /*-------------------------------------------------*/
	/* =  Testimonials
	/*-------------------------------------------------*/

	try { //fade effect
            if(jQuery('.testimonials ul li').length>1){
		jQuery('.testimonials ul').bxSlider({
			adaptiveHeight: true,
			mode: 'fade',
			pager: false
		});
            }
	} catch(err) {

	}
        

	/* ---------------------------------------------------------------------- */
	/*	Contact Map
	/* ---------------------------------------------------------------------- 
	var contact = {"lat":"40.714623", "lon":"-74.006605"}; //Change a map coordinate here!

	try {
		jQuery('#map').gmap3({
		    action: 'addMarker',
		    latLng: [contact.lat, contact.lon],
		    map:{
		    	center: [contact.lat, contact.lon],
		    	zoom: 14
		   		},
		    },
		    {action: 'setOptions', args:[{scrollwheel:false}]}
		);
	} catch(err) {

	}

	/* ---------------------------------------------------------------------- */
	/*	Portfolio
	/* ---------------------------------------------------------------------- 
	
	jQuery('#filterOptions li a').click(function() {
		// fetch the class of the clicked item
		var ourClass = jQuery(this).attr('class');
		
		// reset the active class on all the buttons
		jQuery('#filterOptions li').removeClass('active');
		// update the active state on our clicked button
		jQuery(this).parent().addClass('active');
		
		if(ourClass == 'all') {
			// show all our items
			jQuery('#ourHolder').children('div.item').show();	
		}
		else {
			// hide all elements that don't share ourClass
			jQuery('#ourHolder').children('div:not(.' + ourClass + ')').hide();
			// show all elements that do share ourClass
			jQuery('#ourHolder').children('div.' + ourClass).show();
		}
		return false;
	});
        /*-------------------------------------------------*/
	/* =  portfolio isotope
	/*-------------------------------------------------*/

	var winDow = $(window);
	// Needed variables
	var $container=$('.projects-container');
	var $filter=$('.non-paginated');
	
	try{
		$container.imagesLoaded( function(){
			$container.show();
			$container.isotope({
				filter:'*',
				layoutMode:'masonry',
				animationOptions:{
					duration:750,
					easing:'linear'
				}
			});
		});
	} catch(err) {
		//alert(err);
	}

	winDow.bind('resize', function(){
		var selector = $filter.find('a.active').attr('data-filter');

		try {
			$container.isotope({ 
				filter	: selector,
				animationOptions: {
					duration: 750,
					easing	: 'linear',
					queue	: false,
				}
			});
		} catch(err) {
		}
		return false;
	});
	
	// Isotope Filter 
	$filter.find('a').click(function(){
		var selector = $(this).attr('data-filter');

		try {
			$container.isotope({ 
				filter	: selector,
				animationOptions: {
					duration: 750,
					easing	: 'linear',
					queue	: false,
				}
			});
		} catch(err) {

		}
		return false;
	});


	var filterItemA	= $('.filter-items li a');

	filterItemA.on('click', function(){
		var $this = $(this);
		if ( !$this.hasClass('active')) {
			filterItemA.removeClass('active');
			$this.addClass('active');
		}
	});
        try{
		jQuery("a.btn-icon").fancybox({openEffect  : 'fade',closeEffect : 'fade',prevEffect : 'elastic',nextEffect : 'elastic',closeBtn  : false,helpers : {title : {type : 'inside'},buttons	: {}}});
	} catch(err) {
		
	}
	
	

	/* =  Fancybox Videos
	/*-------------------------------------------------*
	try {
		jQuery('.fancybox-video').fancybox({
			maxWidth	: 800,
			maxHeight	: 600,
			fitToView	: false,
			width		: '70%',
			height		: '70%',
			autoSize	: false,
			openEffect  : 'fade',
			closeEffect : 'fade',
			prevEffect : 'elastic',
			nextEffect : 'elastic',
			closeBtn  : false,
			helpers : {title : {type : 'inside'},buttons	: {}}
		});
	} catch(err) {

	}*/
        jQuery(".fancybox-video").click(function() {
            $.fancybox({
            'padding'       : 0,
            'autoScale'     : false,
            'openEffect ' : 'fade',
             'loseEffect' : 'fade',
            '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;
});
});
/********* Contact Widget *************/
function checkemail(emailaddress){
	"use strict";
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i); 
	return pattern.test(emailaddress); 
}

jQuery(document).ready(function(){ 
	"use strict";
	jQuery('#registerErrors, .widgetinfo').hide();		
	var $messageshort = false;
	var $emailerror = false;
	var $nameshort = false;
	var $namelong = false;
	
	jQuery('#contactFormWidget input#wformsend').click(function(){ 
		var $name = jQuery('#wname').val();
		var $email = jQuery('#wemail').val();
		var $message = jQuery('#wmessage').val();
		var $contactemail = jQuery('#wcontactemail').val();
		var $contacturl = jQuery('#wcontacturl').val();
		var $subject = jQuery('#wsubject').val();
	
		if ($name !== '' && $name.length < 3){ $nameshort = true; } else { $nameshort = false; }
		if ($name !== '' && $name.length > 30){ $namelong = true; } else { $namelong = false; }
		if ($email !== '' && checkemail($email)){ $emailerror = true; } else { $emailerror = false; }
		if ($message !== '' && $message !== 'Message' && $message.length < 3){ $messageshort = true; } else { $messageshort = false; }
		
		jQuery('#contactFormWidget .loading').animate({opacity: 1}, 250);
		
		if ($name !== '' && $nameshort !== true && $namelong !== true && $email !== '' && $emailerror !== false && $message !== '' && $messageshort !== true && $contactemail !== ''){ 
			jQuery.post($contacturl, 
				{type: 'widget', contactemail: $contactemail, subject: $subject, name: $name, email: $email, message: $message}, 
				function(/*data*/){
					jQuery('#contactFormWidget .loading').animate({opacity: 0}, 250);
					jQuery('.form').fadeOut();
					jQuery('#bottom #wname, #bottom #wemail, #bottom #wmessage').css({'border':'0'});
					jQuery('.widgeterror').hide();
					jQuery('.widgetinfo').fadeIn('slow');
					jQuery('.widgetinfo').delay(2000).fadeOut(1000, function(){ 
						jQuery('#wname, #wemail, #wmessage').val('');
						jQuery('.form').fadeIn('slow');
					});
				}
			);
			
			return false;
		} else {
			jQuery('#contactFormWidget .loading').animate({opacity: 0}, 250);
			jQuery('.widgeterror').hide();
			jQuery('.widgeterror').fadeIn('fast');
			jQuery('.widgeterror').delay(3000).fadeOut(1000);
			
			if ($name === '' || $name === 'Name' || $nameshort === true || $namelong === true){ 
				jQuery('#wname').css({'border-left':'4px solid #red'}); 
			} else { 
				jQuery('#wname').css({'border-left':'4px solid #929DAC'}); 
			}
			
			if ($email === '' || $email === 'Email' || $emailerror === false){ 
				jQuery('#wemail').css({'border-left':'4px solid red'});
			} else { 
				jQuery('#wemail').css({'border-left':'4px solid #929DAC'}); 
			}
			
			if ($message === '' || $message === 'Message' || $messageshort === true){ 
				jQuery('#wmessage').css({'border-left':'4px solid red'}); 
			} else { 
				jQuery('#wmessage').css({'border-left':'4px solid #929DAC'}); 
			}
			
			return false;
		}
	});
});