
//Start JQuery
$(function() {

$("a[rel='lang']").colorbox({width:'300px', height:'300px'});
$("a[rel='example1']").colorbox();
		$('#homepage_highlights a').click(function (){
			var str = $(this).attr('rev');
			var lnk = $(this).attr('href');
			
			$('#homepage_highlights a').removeClass('over');
			$('#homepage_highlights_overlay').remove();
			
			$('#homepage_highlights').append('<img id="homepage_highlights_overlay" alt="Sectorlight Hero Image" />',$('a.shut'));
			$('#homepage_highlights_overlay').attr('src', $(this).attr('rel'));
			$('#homepage_highlights a').css('visible', 'hidden');
			$(this).addClass('over');

			$('#headlines').html(str).append('&#8230;&nbsp;<a class="more" href="' + lnk + '">More</a>&nbsp;&raquo;',$('a.shut'));			
			return false;
		});		
		$('#headlines h2').mouseover(function(){
				$('#portfolio_navigation').slideDown(100);
			});
		
		$('#portfolio_navigation').mouseleave(function() {
			$(this).slideUp(100);
		});

	//Contact Us Switches:
		$("#carousel").jCarouselLite({
			circular: false,
			visible: 2,
			scroll: 1,
			btnNext: ".more",
			btnPrev: ".less"
		});

		//Contact Us Switches:
		$("#carousel-projects").jCarouselLite({
		    circular: true,
		    visible: 1,
		    scroll: 1,
		    btnNext: ".more",
		    btnPrev: ".less"
		});	



	//Accordion Function for About Us
		$('#about').find('.hidden').hide().end();
		
		$('a.toggle').click(function() {
			var imgMap = $(this).attr("href");
			$('#about').find(imgMap).show();
			$('#about').find(imgMap).prev().hide();
			return false;
		});

	//$('#portfolio .p-home #utility').find('dd.secDesc:first').show().end();
	//$('#portfolio .p-personal #utility').find('dd.secDesc:eq(1)').show().end();
	//$('#portfolio .p-digital #utility').find('dd.secDesc:last').show().end();
	//$('#portfolio .p-traditional #utility').find('dd.secDesc:last').show().end();


	//Accordion Function for the news page:
	/*
		$('#news').find('.ctrl').text('expand');
		$('#news').find('dd.open').prev('dt').find('.ctrl').text("collapse").end();
		$('#news').find('dd.closed').hide().end().find('dt.expand').click(function() {
			var action = $(this).find('.ctrl');
			var answer = $(this).next();
			if (answer.is(':visible')) {
				action.text("expand");
				answer.slideUp(100);
				
			} else {
				$("dd:visible").slideUp(100).end();
				$("dt.expand").find(".ctrl").text("expand");
				action.text("collapse");
				answer.slideDown(100);
			}
			return false;
		});
		
		var article = $('#title' + locationSearch());
		if(article.is(':not(#title6)')){
			article.trigger('click');
		}
	  
	*/	
		// if there is a hash on the url, filter the links by the hash prop
		var toshow = window.location.hash ? '[hash=' + window.location.hash + ']' : ':first';
		var containers = $('#news dl > dd');
		
		$('#news dl dt a.expand').click(function () {
			if ($(this).find('.ctrl').text() == "collapse"){
				$('#news dl dt a.expand').find('.ctrl').text("expand");
				containers.hide();
			} else {
				containers.hide().filter(this.hash).show().find('.article').show().jScrollPane({
					showArrows: true, 
					scrollbarWidth: 16,
					scrollbarMargin: 10,
					arrowSize: 16,
					dragMaxWidth: 16,
					dragMaxHeight: 370
				});

				$('#news dl dt a.expand').find('.ctrl').text("expand");
				$(this).find('.ctrl').text("collapse");
			}
		}).filter(toshow).click();
		

	//If user wants to print the page, open the articles
	/*
	$.keypress(function (e) {
		  if (e.which == 17 && e.which == 80) {
      		$('#news dl > dd').show();
		});
	*/

	//Erase the dotted line around links
		$('a').click( function() { this.blur(); });
		
	//Add target to external links:
		$('a.external').each( function() {
			$(this).attr("target","_blank");
			$(this).attr("title","This link will open in a new window, please close to return to the Sectorlight website");
		});

	//Add Spy Animation to Testimonials:
	/*
		$('ol.spy').simpleSpy().bind('mouseenter', function () {
    			$(this).trigger('stop');
		}).bind('mouseleave', function () {
        		$(this).trigger('start');
    		});
	*/
	//Solution for Client Login Section:
	/*
		$('a.dataroom').fancybox({
			'hideOnContentClick': false,
			'frameWidth': 500,
			'frameHeight': 400
		}); 
	*/	
	//Solution for the scrolling content
		$('.scroll-pane').jScrollPane({
			showArrows: true, 
			scrollbarWidth: 16,
			scrollbarMargin: 10,
			arrowSize: 16,
			dragMaxWidth: 16,
			dragMaxHeight: 369
		});

		$('.awards-scroll').jScrollPane({
			showArrows: true, 
			scrollbarWidth: 16,
			scrollbarMargin: 10,
			arrowSize: 16,
			dragMaxWidth: 16,
			dragMaxHeight: 550
		});

		$('.testimonial-scroll').show().jScrollPane({
			showArrows: true, 
			scrollbarWidth: 16,
			scrollbarMargin: 10,
			arrowSize: 16,
			dragMaxWidth: 16,
			dragMaxHeight: 550
		});


	}); ///jquery

(function ($) {
    
$.fn.simpleSpy = function (limit, interval) {
    limit = limit || 3;
    interval = interval || 8000;
    
    return this.each(function () {
        // 1. setup
            // capture a cache of all the list items
            // chomp the list down to limit li elements
        var $list = $(this),
            items = [], // uninitialised
            currentItem = limit,
            total = 0, // initialise later on
	    running = true,
            height = $list.find('> li:first').height();
            
        // capture the cache
        $list.find('> li').each(function () {
            items.push('<li>' + $(this).html() + '</li>');
        });
        
        total = items.length;
        
        $list.wrap('<div class="spyWrapper" />').parent().css({ height : height * limit });
        
        $list.find('> li').filter(':gt(' + (limit - 1) + ')').remove();

	$list.bind('stop', function () {
            running = false;
        }).bind('start', function () {
            running = true;
        });

        // 2. effect        
        function spy() {
		if (running){
	            // insert a new item with opacity and height of zero
        	    var $insert = $(items[currentItem]).css({
        	        height : 0,
        	        opacity : 0,
        	        display : 'none'
        	    }).prependTo($list);
        	                
        		    // fade the LAST item out
         	   $list.find('> li:last').animate({ opacity : 0}, 1000, function () {
         	       // increase the height of the NEW first item
         	       $insert.animate({ height : height }, 1000).animate({ opacity : 1 }, 1000);
         	       
         	       // AND at the same time - decrease the height of the LAST item
        	        // $(this).animate({ height : 0 }, 1000, function () {
            		// finally fade the first item in (and we can remove the last)
               	     	$(this).remove();
            		// });
            		});
            
           	 	currentItem++;
            		if (currentItem >= total) {
            		    currentItem = 0;
           	 	}
		}
            
            setTimeout(spy, interval)
        }
        
        spy();
    });
};
    
})(jQuery);

function goBack(){ history.back(-1); }

function openWin(link,w,h,s,t,u,m,r)  {
/****************      SETTINGS      *******************
		'w' =	width
		'h' = 	height
		's' = 	scrollbars - 'yes' or 'no' 
		't' = 	toolbar - 0 / 1
		'u' = 	status - 'yes' or 'no'
		'm' = 	menubar - 0 / 1
		'r' = 	resizeable - 'yes' or 'no'
		
		eg: <a href="javascript:popup2('link[URL]','width[px]','height[px]','scroll[yes/no]','tools[1/0]','status[yes/no]','menu[0/1]','resize[yes/no]');">link item</a>
*******************************************************/
	sH = ((screen.availHeight - h) / 2);
	sW = ((screen.availWidth - w) / 2);
	dummy2=window.open(link,"newindow","address=yes, toolbar="+t+",status="+u+",menuBar="+m+",scrollbars="+s+",resizable="+r+",width="+w+",height="+h+",left="+sW+",top="+sH+"");
}

function closeWin(){
	close();	
}

function locationSearch(){
    var queryString = new String();
    queryString = window.location.search;
    queryString = queryString.substring(1);
    var arr1 = new Array();
    arr1 = queryString.split("&");
    var arr2 = new Array();
    for(var i = 0; i<arr1.length; i++){
        arr2[i] = arr1[i].toString().substring(arr1[i].toString().indexOf("=") + 1);
        arr1[i] = arr1[i].toString().substring(0,arr1[i].toString().indexOf("="));
    }
    return arr2;
} 
