jQuery(function( $ ){


$(window).resize(function() {



	if($(this).width() < 970) { 
			$('body,html').css({'backgroundPosition':'left top','background-image':'url(/images/global-background_left.gif)'});
		} else {
			$('body,html').css({'backgroundPosition':'center top','background-image':'url(/images/global-background.gif)'});
		}});



$(".Form form").validate({
   rules: {
     // simple rule, converted to {required:true}
     fname: "required",
     lname: "required",
     email: {
     			required: true,
				email: true
     }
     
   },
   messages: {
   fname: {  required: "" },      
   lname: {  required: "" },      
    email: {  required: "", email: "" }
   },
    highlight: function(element, errorClass, validClass) {
     $(element).addClass(errorClass).removeClass(validClass);
   
  },
  unhighlight: function(element, errorClass, validClass) {
     $(element).removeClass(errorClass).addClass(validClass);
  }
});



	
if($(window).width() < 970) { 
		$('body,html').css({'backgroundPosition':'left top','background-image':'url(/images/global-background_left.gif)'});
	} else {
		$('body,html').css({'backgroundPosition':'center top','background-image':'url(/images/global-background.gif)'});
	};

$('.Form .TxtInput').focus(function(){ $(this).css('background-color','#e1e1e1'); });
$('.Form .TxtInput').blur(function(){ $(this).css('background-color','#f0f0f0'); });

$('.Slideshow').swipeGallery({
	height: 400,
	width: 780, 
	pager: '.Pager .Buttons',
	captions:'.Text span',
	next: '.Next',
	prev: '.Prev',
	autoScroll: true
});

$('.Portfolio').swipeGallery({
	height: 400,
	width: 780, 
	captions:'.Caps',
	next: '.Next',
	prev: '.Prev',
	pos: '.Position',
	file: '.ImageDownload'
});
$('.SlidesNav A').hover(function(){$("#SlidesNav A").fadeIn(200); },function(){ $("#SlidesNav A").hide();  });

$('.Text span').hide(); 
$('.Captions').hover(
function(){ $(this).find('.Text span').stop(true,true).css('display','block');  },
function(){ $(this).find('.Text span').stop(true,true).css('display','none');  });


$('.Navigator, .Link a').click( function(){
		var loc = this.hash;
		$.scrollTo(loc,{offset: -160,queue:true,duration: 1500});
		return false;
	});

$('.BacktoTop a').click( function(){
		var loc = this.hash;
		$.scrollTo(0,{speed:1000});
		return false;
	});

var d = "";
var t = "";
var i = "";

$('.ProjectButton,.CatFilter').live('click', function() {
$('#Loader H5').html("<span class='Loader'></span> Loading...");
       	
       	d = $(this).attr('href').replace('#','');
        t = $('.Technologies').html();
        i = $('.Industries').html();
        
        if($(this).hasClass("YearFilter Selected")) { 
        $(this).removeClass("Selected");
        y = "||";
        }
     	else if($(this).hasClass("YearFilter")) { 
       		$('.Years').html(d); 
       		var y = d; 
    		$(".YearFilter").removeClass("Selected");
       		$(this).addClass('Selected');       	
       	
       	} else {      
		if($('.Years').html().length > 3){	var y = $('.Years').html(); } else { y="||"; };
		
		if($(this).hasClass("TechnologyButton")){
    	if($(this).hasClass("Selected")){ 
			$(this).removeClass("Selected")		
            t = t.replace(/\|/g,'--|--');
            t = t.replace('--'+d+'--','');
            t = t.replace(/\-/g,'');
         	t = t.replace(/\|\|/g,'|');
            $('.Technologies').html(t);
		} else {
			$(this).addClass("Selected");
			var t = $('.Technologies').html();
            if(t != ""){ t = t+'|'+d+'|'} else { t = '|'+d+'|'; }
       		t = t.replace(/\|\|/g,'|');
        	$('.Technologies').html(t);

		}};
		if($(this).hasClass("IndustryButton")){
		if($(this).hasClass("Selected")){ 
			$(this).removeClass("Selected")		
            i = i.replace(/\|/g,'--|--');
            i = i.replace('--'+d+'--','');
            i = i.replace(/\-/g,'');
         	i = i.replace(/\|\|/g,'|');
            $('.Industries').html(i);
		} else {
			$(this).addClass("Selected");
			var i = $('.Industries').html();
            if(i != ""){ i = i+'|'+d+'|'} else { i = '|'+d+'|'; }
       		i = i.replace(/\|\|/g,'|');
        	$('.Industries').html(i);

		}}
		
		
		
	};

if(t == "|"){
	$('#Loader').load('/index.php/includes/listing/|'+i+'/'+y+'');
	} else if(i == "|"){
	$('#Loader').load('/index.php/includes/listing/|'+t+'/'+y+'');
	}else{
	$('#Loader').load('/index.php/includes/listing/|'+t+'/'+y+'/|'+i+'/');
	};
	
	$('#Loader').delay(600).fadeIn(400);
	return false;
});



var t = "";
var i = "";
var y = "";




if( $('.Technologies').length > 0 || $('.Industries').length > 0 ||  $('.Years').length > 0) {
   if($('.Technologies').html().length > 0){
	   t = $('.Technologies').html().replace('C','|');
	   $('.Technologies').html(t+'|');
   } else { t = ""; }
  
     if($('.Industries').html().length > 0){
	   i = $('.Industries').html().replace('C','|');
	   $('.Industries').html(i+'|');
   } else { i = ""; }
  
  
  if($('.Years').html().length > 0){
	   y = $('.Years').html(); t="||";
	} else { y=""; }
	
	$('#Loader').load('/index.php/includes/listing/'+t+i+'/'+y+'/');
   
};

$(".Form form").validate();
$('.DropDown A.Selected').live('click', function(){ $('.Years').html(''); $('.DropDown DT A').html("Select");  });

$('.DropDown DL').hover( 
function(){ $('.DropDown DD').show(); },
function(){ $('.DropDown DD').hide(); if($('.Years').html() != '') { $('.DropDown DT A').html($('.Years').html()); } else { $('.DropDown DT A').html("Select"); } });


$('#Quotes').cycle({ timeout: 10000, random: true}); 

var loc = document.location.hash;
if(loc.length > 0) { $.scrollTo(loc,{offset: -160,queue:true,duration: 1000}); }
else { 
$('BODY, #SiteWrapper').scrollTo( 0,1 ); 
$.scrollTo( 0 );
}


});









