jQuery(function(){
	//thx to http://chris-barr.com/index.php/entry/disable_text_selection_with_jquery/
	jQuery.extend(jQuery.fn.disableTextSelect = function() {
        return this.each(function(){
            if(jQuery.browser.mozilla){//Firefox
            	jQuery(this).css('MozUserSelect','none');
            }else if(jQuery.browser.msie){//IE
            	jQuery(this).bind('selectstart',function(){return false;});
            }else{//Opera, etc.
            	jQuery(this).mousedown(function(){return false;});
            }
        });
    });
    jQuery('.noSelect').disableTextSelect();//No text selection on elements with a class of 'noSelect'
});

jQuery(document).ready(function() {
	//setup the quick nav list
    jQuery('#quicknavlist').jcarousel({
        'start' : 1,
        'scroll' : 2,
        'wrap' : 'circular'
    });

    //specify the featured projs
    var feaProjs = [
		{
			image : "slide-1.png",
			name : "Electronic World",
			services : ["Website Design", "SEO", "Dedicated server hosting"],
			desc : "SearchQuest developed an advanced e-commerce system for the leading online TV retailer, Electronic World, alongside an on-going SEO campaign achieving first position for 'Cheap TV’"
		},
		{
			image : "slide-2.png",
			name : "Xpress CDs",
			services : ["Web Design", "SEO", "Web App."],
			desc : "Both in designing and developing the website and undertaking a monthly SEO campaign, SearchQuest has built up the online presence of Xpress CDs, obtaining a number one Google position for 'CD Duplication'"
		},
		{
			image : "slide-4.png",
			name : "EMC Advertising Gifts",
			services : ["Web Development", "SEO", "Dedicated server hosting"],
			desc : "Developing a bespoke content management system and handling SEO on the EMC Advertising Gifts website has seen top rankings for a number of high-traffic keyphrases, including a number one position for 'Advertising Gifts'"
		},
		{
			image : "slide-5.png",
			name : "Banks Lyon",
			services : ["Web Design", "SEO", "Custom CMS"],
			desc : "Design, build and SEO, for an authorised watch retailer. Numerous no.1 positions under very competitive key phrases."
		}
    ];
    var feaProjAm = feaProjs.length;
    

    $feaCarousel = jQuery("#featured-cara-list");
    $projDotsDiv = jQuery("#proj-dots");
    $projNavDiv = jQuery("#fea-proj-nav");
    //make the carousel images
	for( var i=0; i<feaProjAm; i++ ){
		$feaCarousel.append( jQuery('<li><img src="/wp-content/themes/sq/images/slides/' + feaProjs[i].image + '" alt="' + feaProjs[i].name + '"  /></li>' ) );
		$projNavDiv.append( jQuery('<div>' + (+i+1) + '</div>' ) );
		$projDotsDiv.append( jQuery('<div></div>') );
	}
	
	//setup the quick nav list
	$feaCarousel.jcarousel({
        'start' : 1,
        'scroll' : 1,
        'wrap' : 'circular',
        'auto' : 6,
        'animation' : 750,
        'easing' : 'linear',
        'buttonNextHTML' : null,
        'buttonPrevHTML' : null,
        initCallback: function(carousel){
        	jQuery("#proj-right-but").bind('click', function(){
        		carousel.next();
        	});
        	jQuery("#proj-left-but").bind('click', function(){
        		carousel.prev();
        	});
        },
        itemVisibleInCallback: {
    		onBeforeAnimation: nextSlideAction
    	}
    });
	carousel = $feaCarousel.data('jcarousel');
	
	jQuery("#fea-proj-nav div").each( function(){
		jQuery(this).click( function(){
			carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		} );
	} );
	
	
	//set text for newly rotated site
	function nextSlideAction(carousel, li, index){
		var slideNum = (index - (Math.ceil(index/feaProjAm)-1)*feaProjAm )-1;
		jQuery("#pi-name").text( feaProjs[slideNum].name );
		jQuery("#pi-desc-box").text( feaProjs[slideNum].desc );
		jQuery("#pi-services-box li").remove();
		jQuery("#proj-dots div").removeClass('dot-on');
		jQuery("#proj-dots div").eq(slideNum).addClass('dot-on');
		jQuery("#fea-proj-nav div").removeClass('dot-on');
		jQuery("#fea-proj-nav div").eq(slideNum).addClass('dot-on');
		for( var i=0; i<feaProjs[slideNum].services.length; i++ ){
			jQuery("#pi-services-box ul").append( jQuery('<li>' + feaProjs[slideNum].services[i] + '</li>' ) );
		}
	};
	nextSlideAction(null,null,1);//do for 1st one

	//the actions for the show/hide info bu on the carousel 
	$bu = jQuery("#proj-show-bu");
	$bu.toggle( 
		function(){
			$bu.css( {
				'backgroundImage' : 'url(/wp-content/themes/sq/images/proj-info-hide-bu.png)',
				'top' : '-7px'
			});
			jQuery("#proj-info-wrap").slideDown( 400, function(){
				
			});
			carousel.stopAuto();
		}, 
		function(){
			jQuery("#proj-info-wrap").slideUp( 400, function(){
				$bu.css({
					'backgroundImage' : 'url(/wp-content/themes/sq/images/proj-info-show-bu.png)',
					'top' : '0'
				});
			} );
			carousel.startAuto();
		}
	);

	//the enlarger for the portfolio page
	jQuery(".pf-img-box-wrap").hover(function() {
		jQuery(this).css({'z-index' : '10'});
		jQuery(this).find('.pf-img-box').addClass("hover").stop()
			.animate({
				width: '650px', 
				height: '454px'
			}, 200);
		
		} , function() {
		jQuery(this).find('.pf-img-box').removeClass("hover").stop()
			.animate({
				width: '365px', 
				height: '255px'
			}, 400);
		jQuery(this).css({'z-index' : '0'});
	});
	
});
