
registerPanelDisplay	= false
signinPanelDisplay		= false


;(function($){
	$(function(){		
		/* Begin dropdown funciton*/
		$('#drop-nav > ul > li').mouseenter(function(){
			$(this).find('ul').css({'left':'-25px'})											 
		})
		$('#drop-nav > ul > li').mouseleave(function(){
			$(this).find('ul').css({'left':'-999999px'})											 
		})
		/* End dropdown funciton*/
		
		/* Begin home page sign in and register button click funciton*/
		$('#registerHereBtn').click(function(){
			window.location = "/register";
		})// End register here btn click function
		
		$('#signInHereBtn').click(function(){
			if(!signinPanelDisplay){
				$('#signin-panel').show()
				$('#register-panel').hide()
				registerPanelDisplay=false
				signinPanelDisplay=true
				return false
			}
			else{
				registerPanelDisplay=true
				signinPanelDisplay=false
			}
		})// End sign in here btn click function
		
		/* End home page sign in and register button click funciton*/
		
		/* file issues */
		$('input.customFile').change(function(){
			$(this).parents('div.imageUploadPanel').find('input.dynamicBtn').attr('disabled', false).removeClass('disabled');
		})
		/* End file issues */
		
		// custom selects
		findAndInitCustomSelects()
		
		// slide show
		funkySlideShowInit()
							   
	})// END OF DOCUMENT READY FUNCTION

})(jQuery)



/****** CUSTOM SELECTS *******/
/**** PLEASE DO NOT EDIT *****/

var customSelectOpened				= false
var $toBeReplacedWithCustomDropdown	= false

function findAndInitCustomSelects(){
	$toBeReplacedWithCustomDropdown = $('select.toBeReplacedWithCustomDropdown')
	if($toBeReplacedWithCustomDropdown.length){
		$toBeReplacedWithCustomDropdown.each(function(i){
			handleCustomSelectIssues( $(this), i );
		})
		
		$('body').click(function(){
			if (customSelectOpened){
				$('.customDropdown ul').css({'left':'-999999px'}).removeClass('opened')
				customSelectOpened = false
			}
		})
	}
} // Ending function findAndInitCustomSelects()

function handleCustomSelectIssues( $customSelectInput, customInputItemNo){
	var selectOptions = ''
	$customSelectInput.find('option').each(function(i){
		selectOptions+='<li'+ (($(this).attr('selected') == true ) ? ' class="selected"' : '') +'>'+$(this).text()+'</li>'
	})
	
	$customSelectInput.css({'visibility':'hidden', 'position':'absolute', 'left':'-999999px', 'top':'0'})
	$customSelectInput.after('<div class="customDropdown"><div class="ul-head"><span>'+$('select.toBeReplacedWithCustomDropdown:eq('+customInputItemNo+') option:selected').text()+'</span><div class="customDropdownArrow"></div></div>'+((selectOptions != '') ? ('<ul>'+selectOptions+'</ul>') : '')+'</div>')
	
	var $customSelectDiv;
	$customSelectDiv		= $('div.customDropdown').eq(customInputItemNo)
	
	$customSelectDiv.css({'zIndex' : 999999 - customInputItemNo , 'width' : $customSelectInput.width(), 'float' : $customSelectInput.css('float'), 'clear' : $customSelectInput.css('clear'), 'margin-top' : $customSelectInput.css('margin-top'), 'margin-right' : $customSelectInput.css('margin-right'), 'margin-bottom' : $customSelectInput.css('margin-bottom'), 'margin-left' : $customSelectInput.css('margin-left') })	
	$customSelectDiv.find('.ul-head').css({'width' : $customSelectInput.width()})
	
	var $customSelectDi_ul	= $customSelectDiv.find('ul')
	$customSelectDi_ul.css({'left':'-999999px', 'width' : $customSelectInput.width()})
	
	$customSelectDiv.find('div.ul-head').click(function(e){
		e.stopPropagation()
		if(customSelectOpened){
			
			if( $customSelectDi_ul.hasClass('opened') ) $customSelectDi_ul.css({'left':'-999999px'}).removeClass('opened')
			else {
				$('div.customDropdown').find('ul').css({'left':'-999999px'}).removeClass('opened')
				$customSelectDi_ul.css({'left':0}).addClass('opened')
				customSelectOpened = true
			}
		}
		else{
			$customSelectDi_ul.css({'left':0}).addClass('opened')
			customSelectOpened = true
		}
	})
	
	$customSelectDiv.find('li').each(function(i){
		var $this_li	= $(this)
		$this_li.css({'width' : $customSelectInput.width() - (parseInt($this_li.css('padding-left'))+parseInt($this_li.css('padding-right')) )  })
		$this_li.click(function(e){
			e.stopPropagation()
			
			// remove and add the selected class
			$customSelectDi_ul.find('li.selected').removeClass('selected')
			$this_li.addClass('selected')
			
			// Remove previously selected option and set the newly selected option
			$customSelectInput.find('option[selected="selected"]').removeAttr('selected')
			$customSelectInput.find('option:eq('+i+')').attr('selected', true)

			// hide the open options
			$customSelectDi_ul.css({'left':'-999999px'}).removeClass('opened')
			customSelectOpened = false
			
			// Replacing the selected text of the upper span
			$customSelectDiv.find('span').html( $this_li.text() )
		})
	})
} // Ending Function handleCustomSelectIssues

/****** CUSTOM SELECTS ENDS *******/


/****** FUNKY SLIDE SHOW ******/

var slidingDelay			= 3000 // This sets the sliding delay to 3 seconds
var slidingSpeed			= 900
var slidingEasing			= 'easeInOutCubic'

var $slidingTray			= false
var $slideShow				= false
var $pageLinks				= false

var $pageLinksLeftArrow		= false
var $pageLinksRightArrow	= false
var $pageLinksContainer		= false

var $slideLeftArrow			= false
var $slideRightArrow		= false

var currentlyRunning		= true
var autoSlidingPointer		= false

var lengthToTravel			= 610
var totalLengthToTravel		= 0
var imageDistanceCount		= 0

var activeImageNo			= 0
var nextActiveImageNo		= 1
var maxImageNo				= 0

function funkySlideShowInit(){
	$slidingTray	= $('#sliding-tray')
	
	if($slidingTray.length) {
		var imageCount	= $slidingTray.find('img').length
		maxImageNo = imageCount - 1
		
		if( imageCount ){
			
			$slideShow				= $('#slideShow')
			$pageLinks				= $slideShow.find('div.pagelinks')
			
			$pageLinksLeftArrow		= $('#pageLinksLeftArrow')
			$pageLinksRightArrow	= $('#pageLinksRightArrow')
			
			$slideLeftArrow			= $('#slideLeftArrow')
			$slideRightArrow		= $('#slideRightArrow')
			
			// Set the width of the $slidingTray
			$slidingTray.width(imageCount * lengthToTravel)
			
			// Crate the page links
			var pageLinksHTML	= '<div id="pageLinksContainer" style="float:left">'
			for(i=1; i<=imageCount; i++){
				pageLinksHTML+='<em>'+i+'</em>'
			}
			pageLinksHTML+='</div>'
			
			$pageLinksLeftArrow.after(pageLinksHTML)
			
			$pageLinksContainer		= $('#pageLinksContainer')
			
			$pageLinksContainer.find('em').each(function(i){
				$(this).click(function(){
					if( !currentlyRunning ){
						clearTimeout(autoSlidingPointer)
						showParticularSlide( i )
					}
				})
			})
			
			$slidingTray.find('img').each(function(i){
				
				var slidingImageIdName	= 'slidingImageNumber'+i
				$(this).attr('id', slidingImageIdName)
				
				if( $(this).hasClass('active') ){
					activeImageNo = i
				}
			})
			
			showFirstImage()
			
			$pageLinksRightArrow.click(function(){
				if(!currentlyRunning){
					clearTimeout(autoSlidingPointer)
					showParticularSlide( nextActiveImageNo)
				}
			})
			
			$pageLinksLeftArrow.click(function(){
				if(!currentlyRunning){
					clearTimeout(autoSlidingPointer)
					showParticularSlide( ((activeImageNo == 0) ? maxImageNo : (activeImageNo-1)) )
				}
			})

			$slideRightArrow.click(function(){
				if(!currentlyRunning){
					clearTimeout(autoSlidingPointer)
					showParticularSlide(nextActiveImageNo)
				}
			})
			
			$slideLeftArrow.click(function(){
				if(!currentlyRunning){
					clearTimeout(autoSlidingPointer)
					showParticularSlide( ((activeImageNo == 0) ? maxImageNo : (activeImageNo-1)) )
				}
			})
			
			
		} // Ending if(imgageCount)
	} // Ending if($slidingTray.length) {
}

function showFirstImage(){
	
	$pageLinksContainer.find('em:eq('+activeImageNo+')').addClass('active')
	autoSlidingPointer = setTimeout( 'showNextSlide()', slidingDelay )
	
	/*
	$slidingTray.animate({'left' : 0},  slidingSpeed, slidingEasing, function(){
		nextActiveImageNo = ( activeImageNo == maxImageNo ) ? 0 : activeImageNo+1
		currentlyRunning = false
	})
	*/
}

function showNextSlide(){
	showParticularSlide(nextActiveImageNo)
}

function showParticularSlide(nextImageToShow){
	
	if(nextImageToShow != nextActiveImageNo){
		nextActiveImageNo = nextImageToShow
	}
	
	currentlyRunning = true
	
	imageDistanceCount = Math.abs( activeImageNo - nextActiveImageNo)
	
	$slidingTray.animate({'left' : - lengthToTravel * nextActiveImageNo},  ( (imageDistanceCount == 1) ? slidingSpeed : Math.round(slidingSpeed * imageDistanceCount * 0.7) ), slidingEasing, function(){
																																																	   		$pageLinksContainer.find('em:eq('+activeImageNo+')').removeClass('active')
		$pageLinksContainer.find('em:eq('+nextActiveImageNo+')').addClass('active')
	
		activeImageNo = nextActiveImageNo;
		nextActiveImageNo = ( activeImageNo == maxImageNo ) ? 0 : activeImageNo+1
		currentlyRunning = false
		
		autoSlidingPointer = setTimeout( 'showNextSlide()', slidingDelay )
	})
}

/****** FUNKY SLIDE SHOW ENDS ******/

/*************************** EASING *****************************************/
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	}
});
/*************************** END EASING *****************************************/
