var $omc = jQuery.noConflict();

$omc(function(){

	// Add the "&raquo;" to the menu 
	jQuery("#access div  ul li ul li").each(function(){
		if(jQuery(this).children('ul').length>0){
			jQuery(this).find('a:first').append('<span class="omc-submenu-arrow"></span>');
		}
	});	 
	
	// Add the dropdown	arrows to the navigation menu
	$omc("#access div > ul > li").each(function(){
		if($omc(this).children('ul').length>0){
			$omc(this).find('ul:first').append('<span class="omc-navigation-pointer"></span>');
		}
	});
	
	// knock out the margin on some floated objects
	$omc("div.omc-product-listing:nth-child(4), div.omc-product-listing:nth-child(7), div.omc-product-listing:nth-child(10), ").css("margin-right", "0px");
	$omc("div.omc-service-box_third:nth-child(3), div.omc-service-box_third:nth-child(6), div.omc-service-box_third:nth-child(9), ").css("margin-right", "0px");
	$omc("div.omc-service-box:nth-child(2), div.omc-service-box:nth-child(4), div.omc-service-box:nth-child(6), ").css("margin-right", "0px");
/*
	// These are the CUFON FONT targets. All elements are targeted individually for complete control. Delete or add as you wish	
	Cufon.replace('div.p_table h1, #omc-ribbon h1, .omc-content h1, h2, h3, h4, h5, h6, a.omc-tagline-button, span.testimonial-excerpt, .omc-twitter-user, .port_4_title,  a.omc-blog-button, .dropcap, .sc_button, a.omc-buy-now', {hover: true});	

	if(jQuery.browser.version.substring(0, 2) == "8." || jQuery.browser.version.substring(0, 2) == "7.") {} else {
		Cufon.replace('a.omc-glass-button, a.sign_up', {textShadow: '#EEE 1px 1px', color: '-linear-gradient(#868686, #000)'});	
		Cufon.replace('h2.col1, h2.col2, h2.col3, h2.col4, h2.col5 ', {textShadow: '#FFF 1px 1px', color: '-linear-gradient(#BBB, #888)'});	 
		Cufon.replace('.omc-tagline h1', {textShadow: '#FFF 1px 1px', color: '-linear-gradient(#555, #aaa)'});		
		Cufon.replace('#omc-ribbon	h1', { textShadow: '#000 1px 1px', color: '-linear-gradient(#FFF, #EEE)'});		
	}
	*/
    // Fix the bug in Webkit browsers that left a gap in the ribbon + also widen the ribbon if the breadcrumb trail is too long
	var ribbonWidth = $omc('#omc-ribbon h1 span.omc-ribbon-middle').width();   
	var trailWidth = $omc('#omc-breadcrumb').width();
	
	ribbonWidth = ribbonWidth + 40;   
    $omc('span.omc-ribbon-right').css('left', ribbonWidth).css('display', 'block');
	
});

$omc(document).ready(function(){	
	
	var $inceptionPortfolioImages = $omc('a.inception-portfolio img'),
		$inceptionPaginationLinks = $omc('a.inception-inactive'),
		$inceptionHeaders = $omc('.inception-header'),
		$inceptionArrows = $omc('a.arrow'),
		$inceptionIconsWrapper = $omc('span.inception-icon-reflect');

	$omc($inceptionHeaders).children('span.inception-toggle').fadeIn(1);	
		 
	 if(jQuery.browser.version.substring(0, 2) == "8." || jQuery.browser.version.substring(0, 2) == "7.") {
		$omc($inceptionArrows).css('display', 'block');
	 } else { 
		$omc($inceptionArrows).animate({opacity: 0.9}, 1).fadeIn(500); // Fades in the Slider Arrows
	 }
	// Animation effect in the MiniSlider portfolio	
	$omc($inceptionPortfolioImages).hover(
		function(){				
			$omc($inceptionPortfolioImages).stop().animate({ opacity: 0.5}, 300 );
			$omc(this).stop().animate({ opacity: 1}, 300 );			
		},
		function(){
			$omc($inceptionPortfolioImages).stop().animate({ opacity: 1}, 300 );		
		}
	);
	
	// The animation for the Product Gallery	
	var $galleryTriggers = $omc('a.gallery_trigger');
		
	$omc($galleryTriggers).hover (
		function() {
			$omc(this).children('span.omc-view-gallery').stop().animate({bottom: 20, opacity:0.5}, 200, 'easeOutQuad');
		},
		function() {
			$omc(this).children('span.omc-view-gallery').stop().animate({bottom: 0, opacity:0}, 200, 'easeOutQuad');		
		}
	);
	
	// Animation for the one column portfolio
	var $oneColImages = $omc('.omc-blog-frame2 img.omc-blog-image');
	
	$omc($oneColImages).hover(
		function(){
			$omc(this).animate({opacity: 0.5}, 400);
		},
		function(){
			$omc(this).animate({opacity: 1}, 400);
		}
	);

	// Hover animation for the Slider Headers
	$omc($inceptionHeaders).hover(
		function(){	
			$omc(this).children('span.inception-header-fade').fadeIn(1);	
			$omc(this).children('span').css('color', 'rgba(255,255,255,0.9)');
		},
		function(){
			$omc(this).children('span.inception-header-fade').fadeOut(300);		
			$omc(this).children('span').css('color', 'rgba(255,255,255,0.6)');		
		}
	);
	
	// Hover animation for the navigation menu	
	var $navigationLinks = $omc('#access div ul li'),
		$submenuAnchors = $omc('#access div ul li ul li a');
	
	if(jQuery.browser.version.substring(0, 2) == "8." || jQuery.browser.version.substring(0, 2) == "7.") {
		$omc($navigationLinks).hover (
			function(){
			$omc(this).find('ul:first').stop(true, true).css('display', 'block');		
			},
			function(){
			$omc(this).find('ul:first').stop(true, true).css('display', 'none');
			}
		);
	} else {
		$omc($navigationLinks).hover (
			function(){
			$omc(this).find('ul:first').stop(true, true).fadeIn(100);		
			},
			function(){
			$omc(this).find('ul:first').stop(true, true).delay(30).fadeOut(200);
			}
		);	
	}
	
	// Put all the testimonial elements into variables :)
	var $testimonialsCompleteWrapper = $omc('.omc-homepage-testimonials-wrapper'),
		$testimonialsWrapper = $omc($testimonialsCompleteWrapper).find('.omc-testimonials-inner-right'),
		$testimonialsPages = $omc($testimonialsWrapper).find('> div'),
		$testimonialsItems = $omc($testimonialsPages).find('> div'),
		$testimonialsColourImages = $omc($testimonialsItems).find('img.omc-testimonial-colour'),
		$testimonialsTriggers = $omc($testimonialsItems).find('a.omc-testimonial-gradient'),
		$testimonialsExcerpts = $omc($testimonialsItems).find('span.testimonial-excerpt'),
		$testimonialsExcerptFirst = $omc($testimonialsExcerpts).first(),
		$testimonialsColourImagesFirst = $omc($testimonialsColourImages).first(),
		$testimonialsFirstPage = $omc($testimonialsPages).first(),
		$testimonialsArrow = $omc($testimonialsCompleteWrapper).find('.omc-testimonials-arrow'),
		$testimonialsArrowTop = $omc($testimonialsArrow).find('.omc-testimonials-arrow-top'),
		pagesAmount = $testimonialsPages.length,
		lastPage = pagesAmount - 1,
		page = 0;

	// Some intitial animations
	$omc($testimonialsExcerptFirst).fadeIn(3000);	// Fade in the first excerpt		
	$omc($testimonialsColourImagesFirst).fadeIn(3000);	// Fade in the first colour logo	
	$omc($testimonialsTriggers).addClass('testimonial-inactive');	// Make all logo inactive
	$omc($testimonialsTriggers).first().removeClass('testimonial-inactive').addClass('testimonial-active'); // make the first active
	$omc($testimonialsFirstPage).fadeIn(3000);	// Fade in the first group of testimonials		
	
	if (pagesAmount <= 1) { 
		$omc($testimonialsArrow).remove();
	}
	
	$omc($testimonialsTriggers).hover( // this controls the hover re-saturation effect in the testimonials
		function(){			
			if($omc(this).hasClass('testimonial-inactive')) {	
				$omc($testimonialsColourImages).stop(true, true).fadeOut(300);
				$omc($testimonialsExcerpts).stop(true, true).fadeOut(300);
				$omc(this).parent('.omc-testimonial-images').children('img.omc-testimonial-colour').stop(true, true).fadeIn(300);			
				$omc(this).parent('span').parent('div').children('.testimonial-excerpt').stop().fadeIn(300);			
			} 
			$omc($testimonialsTriggers).removeClass('testimonial-active').addClass('testimonial-inactive')
			$omc(this).addClass('testimonial-active').removeClass('testimonial-inactive');
		}
	);		
	
	$omc($testimonialsCompleteWrapper).hover(// The arrow animation
		function() {
			$testimonialsArrow.stop().animate({left: 970}, 200, 'easeOutQuad');
			$testimonialsArrowTop.stop().animate({left: -4}, 200, 'easeOutQuad');
		},
		function(){
			$testimonialsArrow.stop().animate({left: 850}, 250, 'easeOutQuad' ); 
			$testimonialsArrowTop.stop().animate({left: 50}, 250, 'easeOutQuad');
		}
	);
	
	$omc($testimonialsArrowTop).click( function() {  // This controls the paging of the testimonials  
		if (page < lastPage) {			
			$omc($testimonialsColourImages).fadeOut(300);
			$omc($testimonialsExcerpts).fadeOut(300);
			$omc($testimonialsPages).filter(':eq('+page+')').fadeOut(300);
			page = page + 1; 
			$omc($testimonialsPages).filter(':eq('+page+')').delay(400).fadeIn(300);
			$omc($testimonialsPages).filter(':eq('+page+')').find('img.omc-testimonial-colour').first().fadeIn(300);
			$omc($testimonialsPages).filter(':eq('+page+')').find('span.testimonial-excerpt').first().fadeIn(300);
			$omc($testimonialsTriggers).removeClass('testimonial-active');
		} else {
			$omc($testimonialsExcerpts).fadeOut(300);
			$omc($testimonialsColourImages).fadeOut(300);
			$omc($testimonialsPages).filter(':eq('+lastPage+')').fadeOut(300);	
			$omc($testimonialsFirstPage).delay(400).fadeIn(300);	
			$omc($testimonialsExcerptFirst).fadeIn(300);			
			$omc($testimonialsColourImagesFirst).fadeIn(300);	
			$omc($testimonialsTriggers).removeClass('testimonial-active');
			page = 0;
		}
	});
	
	// Portfolio 4 Column Animations
	$omc(".portfolio_item_4_col").hover(
		function(){
		$omc(this).children("a.frame").stop().animate({ top: "-15px"}, 300, 'easeOutQuad' );
		$omc(this).children(".portfolio_item_4_col span.portfolio_shadow").stop().animate({ bottom: "-7px", opacity: 0.2}, 300);
		$omc(this).children("div.portfolio_item_4_col.description span.portfolio_shadow").stop().animate({ top: "154px", opacity: 0.2}, 300);
		$omc(this).children("a.frame").children("span.portfolio_loading").children("img").stop().animate({ opacity: 0}, 1000 , 'easeOutQuad' );
		},
		function(){
		$omc(this).children("a.frame").stop().animate({ top: "0px"}, 600, 'easeOutQuad' );
		$omc(this).children(".portfolio_item_4_col span.portfolio_shadow").stop().animate({ bottom: "0px", opacity: 1}, 300);
		$omc(this).children("div.portfolio_item_4_col.description span.portfolio_shadow").stop().animate({ top: "147px",  opacity: 1}, 600);
		$omc(this).children("a.frame").children("span.portfolio_loading").children("img").stop().animate({ opacity: 1}, 600 , 'easeOutQuad' );	
		}
	);	
	
	$omc("span.portfolio_loading img, img.omc-product-frame, img.omc-header-image").removeAttr("title");

	// centres the ribbon on the header
	var headerHeight = $omc("img.omc-header-image").height(),
		headerCentred = headerHeight / 2 - 32;
		
	if (headerHeight != 0) {	
		$omc("div#omc-ribbon").css("top",  headerCentred  + "px");	
	}
	
	// Shortcode animation - Show/Hide
	$omc("a.show_hide").toggle(
		function(){
			$omc(this).parent("div").children("div").fadeIn(300);
		},
		function() {
			$omc(this).parent("div").children("div").fadeOut(300);
		}
	);	

	//Code for the Tabs Shortcode
	$omc(".omc-tab-content").hide(); 
	$omc("ul.omc-tabs li:first").addClass("active").show(); 
	$omc(".omc-tab-content:first").show(); 
	
	$omc("ul.omc-tabs li").click(function() {
		$omc("ul.omc-tabs li").removeClass("active"); 
		$omc(this).addClass("active"); 
		$omc(".omc-tab-content").hide(); 
		var activeTab = $omc(this).find("a").attr("href"); 
		$omc(activeTab).fadeIn(500); 
		return false;
	});

	//Initialising Fancybox
	$omc("a.fancybox, a.fancybox-image").fancybox({
		'opacity'			: true,
		'overlayShow'		: true,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'easingIn'      	: 'easeOutBack',
		'easingOut'    		: 'easeInBack',
		'showNavArrows'		: true,
		'cyclic'			: true,
		'padding'			: 5
	});	
	
	$omc("a.video-modal-anchor").fancybox({
		'opacity'			: true,
		'overlayShow'		: true,
		'width'				: 800,
		'height'			: 460,
		'autoScale'			: false,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'easingIn'      	: 'easeOutBack',
		'easingOut'     	: 'easeInBack',
		'type'				: 'iframe',
		'cyclic'			: true,
		'padding'			: 5
	});
	
	$omc("a.portfolio-modal-anchor").fancybox({
		'opacity'			: true,
		'overlayShow'		: true,
		'width'				: 1020,
		'height'			: 590,
		'autoScale'			: false,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'easingIn'      	: 'easeOutBack',
		'easingOut'    		: 'easeInBack',
		'type'				: 'iframe',
		'cyclic'			: true,
		'padding'			: 5
	});
	
	if(jQuery.browser.version.substring(0, 2) == "8." || jQuery.browser.version.substring(0, 2) == "7.") { } else {
		$omc("#omc-ribbon").animate({opacity: 1}, 1000); 

	}
	
	$phoneWidth = $omc('span#omc-phonenumber').width();		
	
	if ($phoneWidth > 1 ) {	
		$phoneWidth = $phoneWidth + 80;	
		$omc('span#omc-wpml-widget').css( 'margin-right' ,  $phoneWidth + 'px'); 
	} else {
		$omc('span#omc-wpml-widget').css( 'margin-right' ,  '30px'); 
	} 

});

$omc(window).load(function() {

	if(jQuery.browser.version.substring(0, 2) == "8." || jQuery.browser.version.substring(0, 2) == "7.") { } else {
		$omc("div.inception-revealed-content").animate({opacity: 1}, 300);
	}
			
	//Pixastic Desaturate Controls
	$omc('img.omc-testimonial-bw, img.bw').pixastic('desaturate');
	
	$omc(".portfolio_item_4_col span.vignette_portfolio  span").fadeIn(300);
	
	$omc("span.omc-testimonial-images").css('background-image', 'none');
	
});

