 /**
 * RV.org.tr FrontEnd Functions 
 * http://www.rv.org.tr
 * @author: artuc <mustafa@igoa.in>
 * @company: iGOA <http://www.igoa.in>
 **/

var internalJobs;
var internalAnnouncement;
$(function(){
	windowWidth = $('body').innerWidth();
	windowHeight = ($('body').innerHeight())+18;

	jobsCount  = 1;
	announcementCount  = 1;
	Cufon.replace('.dinFont, h2, h3', { fontFamily: 'DIN', hover:true });
	Cufon.replace('.dinFontNoHover, h2, h3', { fontFamily: 'DIN', hover:false });
	Cufon.now();
	
	//Search input
	$('.searchInput').click(function(){
		if($(this).val() == "Arama")
			$(this).val('');
		else
			$(this).val('Arama');
	});
	
	//Main Menu Interactions
	$('.mainNav .subMenuContainer').mouseover(function(){
		$(this).parent().find('span.dinFont').css('color', 'black');
		Cufon.refresh();
	}).mouseout(function(){
		$(this).parent().find('span.dinFont').css('color', 'white');
		Cufon.refresh();
	});
	
	$('.mainNav span.dinFont').mouseover(function(){
		$(this).css('color', 'black');
		Cufon.refresh();
	}).mouseout(function(){
		$(this).css('color', 'white');
		Cufon.refresh();
	});
	
	//Content Image Gallery (Right Side)
	$('.btnThmb').live('click', function(){
		$('.selectedContentImage').append("<div class='loadingIndicator'></div>");
		$('.selectedContentImage').load($(this).attr('href'));
		
		$('.selectedThmb').removeClass('selectedThmb');
		$(this).addClass('selectedThmb');
		//$('.loadingIndicator').remove();
		return false;
	});
	
	//Calendar Event Details Popup Opener and Rest.
	$('.monthDays a').click(function(){
		$('.eCalendarDetailsContainer').slideUp();
		$('.eCalendarDetailsContainer').load($(this).attr('href'), function(){	
			$('.monthDays .selectedDay').removeClass('selectedDay');
			$(this).addClass('selectedDay');
			$('.eCalendarDetailsContainer').slideDown();
			Cufon.refresh();
		});
		return false;
	});
	
	//Close button in Calendar Details Popup
	$('.btnEclose').live('click',function(){		
		$('.eCalendarDetailsContainer').slideUp();
		$('.monthDays .selectedDay').removeClass('selectedDay');
		return false;
	});
	
	//Month List in Calendar Details Popup
	$('.monthsLabel').live('click', function(){
		if(!$('.monthsContainer').hasClass('openedState')){
			$('.monthsContainer').animate({width: '523px'}, 330);
			$('.monthsContainer').addClass('openedState');			
		}else{
			$('.monthsContainer').animate({width: '60px'}, 330);
			$('.monthsContainer').removeClass('openedState');
		}
	});
	
	//Event Calendar List Page - Date Animation.
	$('.eventListContainer').mouseenter(function(){
		$(this).find('.dateContainer').animate({left: '0px'}, 300);
	}).mouseleave(function(){
		$(this).find('.dateContainer').animate({left: '-70px'}, 300);
	});
	
	//Blog Gallery Animations
	$('.blogImage').mouseenter(function(){
		$(this).find('span').slideDown();
	}).mouseleave(function(){
		$(this).find('span').slideUp();
	});
	
	//Event Details Program Opener
	$('.btnProgram').click(function(){
		$('.eventProgramContainer').slideToggle();
		return false;
	});
	
	//Gallery Images, LightBox Opener
	$(".btnColorBox").colorbox();
	$(".btnInlineLightBox").click(function(){
		$('.lightBoxOverlay').css({width: windowWidth, height: windowHeight}).fadeIn();
		$('#ikFormContainer').fadeIn();
	});
	
	$('.lightBoxOverlay, .ikForm .btnClose').live('click', function(){
		$('.lightBoxOverlay, .mLightBoxes').fadeOut();
	});
	
	
	$(".btnIkYonetim").colorbox({iframe:true, width:'260px',height:'110px'});
	$(".btnEventApply").colorbox({iframe:true, width:'780px',height:'480px', href:"event/apply/citirFikir"});
	$(".btnEventApplyCannes").colorbox({iframe:true, width:'780px',height:'615px', href:"event/cannesApply"});
	$(".btnEventApplyYazOkulu").colorbox({iframe:true, width:'600px',height:'440px', href:"event/yazOkuluApply"});
	
	//Gallery Image Rollovers
	$('.gallery li a').mouseenter(function(){
		$(this).append('<div class="galleryHover"></div>');
		$(this).find('.galleryHover').fadeIn();
	}).mouseleave(function(){
		$(this).find('.galleryHover').remove();
	});

	//Form Fields
	$(".mFields").live('click',function(){			
		if($(this).val() == $(this).attr('title')){			
			$(this).val("");
		}
	});

	$('.mFields').blur(function(){
		if($(this).val() == ""){
			$(this).val($(this).attr('title'));
		}
	});
	
	$('.btnAccordion').click(function(){
		if(!$(this).hasClass('openState')){
			$('.openState').removeClass('openState');
			$('.accordionContent').slideUp();
			$(this).addClass('openState');
			$(this).parent().next('div').slideToggle();
		}else{
			$('.openState').removeClass('openState');
			$('.accordionContent').slideUp();
		}
	});

	//Lightbox Closer
	$(".closeBtn, .welcomeTextOverlay").live('click', function(){
		$(".welcomeTextOverlay").slideUp();
	});

	$(".welcomeText").live('click',function(){
		return false;
	});
	
	//RV Generic Accordion <artuc>
	var activeCarouselElem = 0;
	$('.rvCarousel').css('width', $('.rvCarousel li').length * 755+'px');
	$('.carouselPagination li').click(function(){
		findElem = $('.rvCarousel li:eq('+$(this).index());
		activeCarouselElem = $(this).index();
		$('.rvCarousel').animate({
			'left':  '-'+755*$(this).index()+'px'
		}, 500);
	});

	$('.carouselController li.next').click(function(){
		if(activeCarouselElem+1 < $('.rvCarousel li').length){
			activeCarouselElem++;
			$('.rvCarousel').animate({
				'left' : '-=755'
			}, 500);
		}
	});
	$('.carouselController li.prev').click(function(){
		if(activeCarouselElem != 0){
			activeCarouselElem--;
			$('.rvCarousel').animate({
				'left' : '+=755'
			}, 500);
		}
	});	
	
    internalJob = setTimeout(changeJob, 5000);
    internalAnnouncement = setTimeout(changeAnnouncement, 5000);
}); 
//Change Announcement By Interval
function changeAnnouncement(){
    if(announcementCount < $('.mainPageAnnouncementContainer p span a').length){                             
            $('.mainPageAnnouncementContainer p span').animate({'top':'-=42'}, 250);
            announcementCount++;
    }else{
            announcementCount = 1;
            $('.mainPageAnnouncementContainer p span').animate({'top':'0'}, 300);
    }
    internalAnnouncement = setTimeout(changeAnnouncement, 5000);
}

//Change Job By Interval
function changeJob(){                           
    if(jobsCount < $('.mainPageJobsContainer p span a').length){                            
            $('.mainPageJobsContainer p span').animate({'top':'-=55'}, 250);
            jobsCount++;
    }else{
            jobsCount = 1;
            $('.mainPageJobsContainer p span').animate({'top':'0'}, 300);
    }
    internalJob = setTimeout(changeJob, 5000);
}
