﻿  jQuery(function() {
	
	function mainmenu(){
		jQuery(" #menu ul ul ").css({display: "none"}); // Opera Fix
		jQuery(" #menu ul li").hover(function(){
		jQuery(this).find('ul:first').css({visibility: "visible",display: "none"}).show(200);
		},function(){
		jQuery(this).find('ul:first').css({visibility: "hidden"});
	});
	}

 	jQuery(document).ready(function(){
		mainmenu();
	});
	
	/* This is basic - uses default settings */
	$("a.project-list-thumb").fancybox();
	
	$("a.image").fancybox();
	
	$(".gallery a").fancybox();
		
	/* Using custom settings */
		
	$("a#inline").fancybox({
			'hideOnContentClick': true
	});
	
	/* Apply fancybox to multiple items */
	$(".youtube_video").click(function() {
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'		    : 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

	return false;
	
	});
	
	$(".vimeo_video").click(function(){
		$.fancybox({
			'padding':0,
			'autoScale':false,
			'transitionIn':'none',
			'transitionOut':'none',
			'title':this.title,
			'width':600,
			'height':398,
			'href':this.href.replace(new RegExp("([0-9])","i"),'moogaloop.swf?clip_id=$1'),'type':'swf'
			});
	return false;
	
	});
	
	$(".iframe").fancybox({ 
        'type' : 'iframe' 
    });
	
	$(".login_form").fancybox({
		'titlePosition'		: 'inside',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});
	
	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
	
	//Toggle
	jQuery(".togglebox").hide();
	//slide up and down when click over heading 2
	
	jQuery("h4").click(function(){
	// slide toggle effect set to slow you can set it to fast too.
	jQuery(this).toggleClass("active").next(".togglebox").slideToggle("slow");
	
	return true;
	
	});
	
	// function search
	var inactive = "inactive";
    var active = "active";
    var focused = "focused";

    jQuery("label.auto_clear").each(function(){      
        obj = document.getElementById(jQuery(this).attr("for"));
        if((jQuery(obj).attr("type") == "text") || (obj.tagName.toLowerCase() == "textarea")){           
            jQuery(obj).addClass(inactive);          
            var text = jQuery(this).text();
            jQuery(this).css("display","none");          
            jQuery(obj).val(text);
            jQuery(obj).focus(function(){    
                jQuery(this).addClass(focused);
                jQuery(this).removeClass(inactive);
                jQuery(this).removeClass(active);                                  
                if(jQuery(this).val() == text) jQuery(this).val("");
            }); 
            jQuery(obj).blur(function(){ 
                jQuery(this).removeClass(focused);                                                    
                if(jQuery(this).val() == "") {
                    jQuery(this).val(text);
                    jQuery(this).addClass(inactive);
                } else {
                    jQuery(this).addClass(active);       
                };              
            });             
        };  
    }); 
	
	// fade in #back-top
	jQuery(function () {

		// scroll body to 0px on click
		jQuery('.backtop a').click(function () {
			jQuery('body,html').animate({
				scrollTop: 0
			}, 800);
			return false;
		});
	});
	
	var currentPosition = 0;
	var slideWidth = 960;
	var slides = jQuery('.slideContent');
	var numberOfSlides = slides.length;

	// Remove scrollbar in JS
	jQuery('#slidesContainer').css('overflow', 'hidden');

	// Wrap all .slides with #slideInner div
	slides
		.wrapAll('<div id="slideInner"></div>')
	    // Float left to display horizontally, readjust .slides width
		.css({
	      'float' : 'left',
	      'width' : slideWidth
	});

	// Set #slideInner width equal to total width of all slides
	jQuery('#slideInner').css('width', slideWidth * numberOfSlides);

	// Insert controls in the DOM
	jQuery('#contentSlider')
	.prepend('<span class="control" id="leftControl">Clicking moves left</span>')
	.append('<span class="control" id="rightControl">Clicking moves right</span>');

	// Hide left arrow control on first load
	manageControls(currentPosition);

	// Create event listeners for .controls clicks
	jQuery('.control')
	    .bind('click', function(){
	    // Determine new position
		currentPosition = (jQuery(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;
	    
		// Hide / show controls
	    manageControls(currentPosition);
	    // Move slideInner using margin-left
	    jQuery('#slideInner').animate({
	      'marginLeft' : slideWidth*(-currentPosition)
	    });
	});

	// manageControls: Hides and Shows controls depending on currentPosition
	function manageControls(position){
	    // Hide left arrow if position is first slide
		if(position==0){ jQuery('#leftControl').hide() } else{ jQuery('#leftControl').show() }
		// Hide right arrow if position is last slide
	    if(position==numberOfSlides-1){ jQuery('#rightControl').hide() } else{ jQuery('#rightControl').show() }
	}	
	
	$(".rounded-img, .rounded-img2").load(function() {
	    $(this).wrap(function(){
	      return '<span class="' + $(this).attr('class') + '" style="background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;" />';
	    });
	    $(this).css("opacity","0");
	 });

  });


