


$(function(){
  $("#slides").slides({
	//generateNextPrev: true,
	fadeSpeed: 750,
play: 5000,
pause: 2500,
hoverPause: true,
animationStart: function(current){
$('.caption').animate({
bottom:0
},100);
},
animationComplete: function(current){
$('.caption').animate({
bottom:0
},200);
},
slidesLoaded: function() {
$('.caption').animate({
bottom:0
},200);
}
  });
});


$(document).ready(function() {
	
	//contact form
	
	
//$("select, input:checkbox, input:radio, input:file").uniform();

	$('form.iphorm').iPhorm();
	
	// Tooltip settings
	if ($.isFunction($.fn.qtip)) {
		$('.iphorm-tooltip').qtip({
			content: {
				text: false
			},
			style: {
				tip: 'leftMiddle',
				name: 'blue'
			},
			position: {
				corner: {
					target: 'rightMiddle',
					tooltip: 'leftMiddle'
				}
			}
		});
	}
	
	var subjectHtml = $('.subject-input-wrapper').html();
	
	$('#subject').live('change', function () {		
		if ($(this).val() == 'Other') {
			$('.subject-input-wrapper').empty();
			newHtml = $('<input name="subject" type="text" id="subject" value="" />');
			$('.subject-input-wrapper').html(newHtml);
			$cancelOther = $('<a>').click(function () {
				$('.subject-input-wrapper').empty();
				$('.subject-input-wrapper').append(subjectHtml);
				$(this).remove();
				return false;
			}).attr('href', '#').addClass('cancel-button').attr('title', 'Cancel');
			newHtml.after($cancelOther);
		}
	});


	

	if (jQuery().slides) {

jQuery("#slides").hover( function() {
jQuery('.slides-nav').fadeIn(400);
}, function () {
jQuery('.slides-nav').fadeOut(400);
});

}
	
	$(".item-hover").hover(function(){
$(this).find(".portfolio-thumbnail").stop(true, true).animate({ opacity: 'show' }, 1000);
}, function() {
$(this).find(".portfolio-thumbnail").stop(true, true).animate({ opacity: 'hide' }, 1000);
});
$("a[data-rel^='prettyPhoto']").prettyPhoto({opacity:0.80,default_width:500,default_height:344,animationSpeed:'slow',hideflash:true,deeplinking: false,modal:false, theme:'light_rounded'});

if ($('#fancyGallery').length != 0) {

$('#fancyGallery').fancygallery({slideTitle:true,thumbHeight:180,thumbWidth:290,thumbOpacity:0.8,shadowImage: '../images/fancygallery/shadow1.png',boxOptions: {animationSpeed:'slow',deeplinking: false,hideflash:true,modal:false, overlay_gallery: true, theme:'light_rounded'}});
}
//invidual pages
if ($('.slideshowpage').length != 0) {
   $('.slideshowpage').cycle({
	fx:    'fade', 
    speed:  2500,
	 pause:  1 
	});
		}
	
	
	if ($('#cmsVideo').length != 0) {
		
		
$('#cmsImages').hide();
$('#vid a').addClass('active');

$('#img a').click(function() {
//$('#flashcontent').toggle(400);
$('#cmsVideo').fadeOut("fast", function() {
$('#cmsImages').fadeIn("slow");});



$(this).addClass('active');
$('#vid a').removeClass('active');
return false;
});

$('#vid a').click(function() {
//$('#flashcontent').toggle(400);
$('#cmsImages').fadeOut("fast", function() {
$('#cmsVideo').fadeIn("slow");});


$(this).addClass('active');
$('#img a').removeClass('active');
return false;
});
}

if ($('.preloadme').length != 0) {
    $(".preloadme img").preloader({ 
  Style 	: "default",
  Height	: 125,
  Width	: 210,
  Title	: 0 
   });	
 }
	
	
if ($('.preloadpost').length != 0) {
    $(".preloadpost img").preloader({ 
  Style 	: "default",
  Height	: 120,
  Width	: 160,
  Title	: 0 
   });	
	 }	
	//google map 
	if ($('#googlemap').length != 0) {
	//alert('google map');
	initialize();
	}

//for the commenting system
	/* The following code is executed once the DOM is loaded */
	
	/* This flag will prevent multiple comment submits: */
	var working = false;
	
	/* Listening for the submit event of the form: */
	$('#addCommentForm').submit(function(e){

 		e.preventDefault();
		if(working) return false;
		
		working = true;
		$('#submit').val('Working..');
		$('span.error').remove();
		
		/* Sending the form fileds to submit.php: */
		$.post('_le/_cms_submit.php',$(this).serialize(),function(msg){

			working = false;
			$('#submit').val('Submit');
			
			if(msg.status){

				/* 
				/	If the insert was successful, add the comment
				/	below the last one on the page with a slideDown effect
				/*/

				$(msg.html).hide().insertBefore('#addCommentContainer').slideDown();
				$('#body').val('');
			}
			else {

				/*
				/	If there were errors, loop through the
				/	msg.errors object and display them on the page 
				/*/
				
				$.each(msg.errors,function(k,v){
					$('label[for='+k+']').append('<span class="error">'+v+'</span>');
				});
			}
		},'json');

	});


if ($('#twitterID').length != 0) {
	twitID = $('#twitterID').val();  
	 //alert(twitID);
$(".tweet").tweet({

	
 username: twitID,
 join_text: null,
 avatar_size: null,
 count: 1,
 auto_join_text_default: "we said,", 
 auto_join_text_ed: "we",
 auto_join_text_ing: "we were",
 auto_join_text_reply: "we replied to",
 auto_join_text_url: "we were checking out",
 loading_text: "loading tweets..."
 });

}


 });

//other functions


		//menu

var arrowimages={down:['', ''], right:['', '']}
var jqueryslidemenu={
animateduration: {over: 200, out: 200},
buildmenu:function(menuid, arrowsvar){
jQuery(document).ready(function($){
$(" #main_navigation 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(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(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)
}
) 
})
$mainmenu.find("ul").css({display:'none', visibility:'visible'})
})
}
}
jqueryslidemenu.buildmenu("main_navigation", arrowimages)





