/**
	Socea Cristian Pavel
	www.soceacristian.ro
	(C)2009 Toate drepturile asupra acestui
	script sunt rezervate de Socea Cristian Pavel
*/

$(document).ready(function(){

	var doc = $(this);
	
	if((jQuery.browser.msie && jQuery.browser.version.substr(0,1)=="6")) {
		$('#celebrate').ifixpng();
		$('#portfolio-clients').ifixpng();
	}
	$('a[rel=external]').attr("target","_blank");
	
	// adv without boundaries
	$('#awb1').fadeOut(5000);
	$('#awb2').fadeIn(5000);
	
	
	
	$('div.agenda_photos a').prettyPhoto({allow_resize:false});
	$('.agenda .view').click(function(e){
		e.preventDefault();
		$(this).parent().find('.agenda_photos a').eq(0).click();
	});
	
	
	
	
	$("#cm-button .content").css({opacity:0,display:'block'}).find('a').attr('target','_blank');
	$("#cm-button .trigger").css({cursor:'pointer'}).click(function(){
		$("#cm-button").stop().animate({width:180});
		$("#cm-button .trigger").stop().animate({opacity: 0}, 100, function() {$(this).css({display:'none'});});
		$("#cm-button .content").stop().animate({opacity: 1});

	});
	$("#cm-button .content a").bind('mouseleave', function(){
		//alert(1);
		$("#cm-button").stop().animate({width:40});
		$("#cm-button .trigger").css({display:'block'}).stop().animate({opacity: 1});
		$("#cm-button .content").stop().animate({opacity: 0});
	});
	
	
	
	/**
	 * services interaction
	 * 
	 */
	var services = $('#services-accordion div.service');
	var servicesNav = $('.services-content-wrapper #sidebar-services')
	var hash = location.hash;
	
	services.find('.sv-images a').lightBox();
	
	// setup services content
	services.each(function(n){
		$(this).find('h2 a').click(function(e) {
			e.preventDefault();
			var sid = $(this).attr('sid');
			if(!$('#'+sid).hasClass('selected')) {
				$('.service.selected').removeClass('selected').find('.sv-content').slideUp();
				$('#'+sid).addClass('selected').find('.sv-content').slideDown(400, function(){
					$.scrollTo($('#'+sid), 400, function(){
						location.hash = sid;
					});
				});
				servicesNav.find('a.selected').removeClass('selected');
				servicesNav.find('a[sid='+sid+']').addClass('selected');
			} else {
				$('#'+sid).removeClass('selected').find('.sv-content').slideUp();
			}
		});
	});
	
	// setup services side navigation
	servicesNav.find('ul li a').each(function(n) {
		$(this).click(function(e){
			e.preventDefault();
			console.log($(this).attr('sid'));
			$('#'+$(this).attr('sid')).find('h2 a').click();
		});
	});
	
	if(hash.length > 0) {
		$(hash).find('h2 a').click();
		console.log(hash);
	}
	
	/*
	 * keep services "on screen" while scrolling
	 */
	doc.scroll(function(e){
		var navTopMin = 220;
		if(doc.scrollTop() > navTopMin) {
			servicesNav.css({marginTop: (doc.scrollTop() - navTopMin)});
		}
	});

	/*
	var serviceId = 0;
	url = location.href;
	index = url.substr(url.indexOf('#')+1);
	if((url.indexOf('#') > 0) && Number(index)) {
		serviceId = Number(index);
	}
		
	$('#services-accordion').accordion({
		autoHeight: false,
		collapsible: true,
		active: serviceId

	}).bind('accordionchange', function(event, ui) {
		$.scrollTo($('h2.ui-state-active'), 1000);
	});
	
	$('.sv-images a').lightBox();

	$('#client-button').hide();
	$('#content-wrapper').mouseover(function(e){
			
			e.stopPropagation();e.preventDefault();
			
			$('#client-side a img').stop(true,true).fadeTo(400, .4, function(){
				$('#client-button').fadeIn(400);
			});
			$('#main-side p').css({borderColor:'#E0E0E0'});
		}).mouseleave(function(e){
			
			e.stopPropagation();e.preventDefault();
			
			$('#client-side a img').stop(true,true).fadeTo(200, 1, function(){
				$('#client-button').stop(true,true).fadeOut(500);
			});
			$('#main-side p').css({borederColor:'#E5E5E5'});
			
		});

		if(!(jQuery.browser.msie && (jQuery.browser.version.substr(0,1)=="6" || jQuery.browser.version.substr(0,1)=="7"))) {
			$('div.service')
				.css()
				.unbind('mouseover')
				.unbind('mouseout')
				.bind('mouseover', function(){
				
					$(this)
						.siblings()
						.stop().fadeTo(100, 0.3)
						.find('.shade').show();
					$(this).find('.button').stop().animate({marginTop: '5px'}, 100);
				
				})
				.bind('mouseout', function(){
				
					$(this).stop().fadeTo(400, 1).css({textShadow: "none"});
					$(this).siblings().stop().fadeTo(400, 1).css({textShadow: "none"});;
					$(this).siblings().find('.shade').hide();
					$(this).find('.button').stop().animate({marginTop: '0px'}, 100);
				
				});
	}*/
});
