//LEGAL AGE CONDITIONAL
$(document).ready(function() {		
	//Put in the DIV id you want to display
	launchWindow('#splash');
	
	//if close button is clicked
	$('#close').click(function () {
		$('#mask').fadeOut("slow");
		$('#splash').fadeOut("fast");
		$.cookie("legalage", "cyrus", { expires: 1, path: '/' });
		return false;
	});				
	
});

$(document).ready(function(){
    if ($.cookie("legalage")) {    
        $('#mask').css({"display":"none"});
		$('#splash').css({"display":"none"});   
    }  
});

function launchWindow(id) {
	
		$('#splash').css({"display":"block"});
		$('#mask').css({"display":"block"});
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn("fast");	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
		
		//Set the popup window to center
        $(id).css('left', winW/2-$(id).width()/2);
}

//SHOW HIDE
$(document).ready(function() {
 // hides the slickbox as soon as the DOM is ready
  $('.showhide').hide();
 // shows the slickbox on clicking the noted link  
  $('.newsletter').click(function() {
    $('.showhide').show('slow');
    return false;
  });
 // hides the slickbox on clicking the noted link  
  $('.close').click(function() {
    $('.showhide').hide('fast');
    return false;
  });
});

//LIGHTBOX
$(document).ready(function() {
 // hides the slickbox as soon as the DOM is ready
  $('.showhidemap').hide();
 // shows the slickbox on clicking the noted link  
  $('.map').click(function() {
    $('.showhidemap').show('slow');
    return false;
  });
 // hides the slickbox on clicking the noted link  
  $('.closemap').click(function() {
    $('.showhidemap').hide('fast');
    return false;
  });
});

//SLIDE SHOW
$(document).ready(function() {
    var h, 
        hash = window.location.hash, 
        hashes = {},
        index = 0;
        
	$('#slide img').each(function(i) {
	    h = $(this).attr('title');
	    hashes[h] = i;
    });

	if (hash)
		index = hashes[hash.substring(1).split('_')[0]] || index;
		
    $('#slide').cycle({ 
        fx:     'fade', 
        startingSlide: index, // <-- don't forget this!
        speed:  'fast', 
        timeout: 0,
		activePagerClass: 'active',
        pager:  '.timeline', 
        pagerAnchorBuilder: function(idx, slide) { 
            // return selector string for existing anchor 
            return '.timeline li:eq(' + idx + ') a';
        },
        after: function(curr,next,opts) {
                if (typeof $(".scroll-slider").slider('value') == 'number') {
		    h = $(this).find('img').attr('title') + '_' + $(".scroll-slider").slider('value');
			window.location.hash = h;
		}}
    });

	// Variable to hold scroll type
	var slideDrag,
	// Width of .scroll-content ul
	slideWidth = 620,
	// Speed of animation in ms
	slideSpeed = 400,
	animated = false;
	
	// Initialize sliders
	$(".scroll-slider").slider({
		animate: slideSpeed,
		start: checkType,
		slide: doSlide,
		change: doSlide,
		max: slideWidth,
                stop: function(event, ui) { pos=window.location.hash.split('_'); window.location.hash = pos[0]+'_'+ui.value}
	});

	
	// Set each slider to a value
	$(".scroll-slider").each(function(index){
		$(this).slider({ value: window.location.hash.substring(1).split('_')[1] || 0 });
	});
	
	// You can also change a slider at any time like so:
	// $(".scroll-slider:eq(0)").slider("value", value);
	//
	// That would move the first slider to a value, along with its content
	
	function checkType(e){
		slideDrag = $(e.originalEvent.target).hasClass("ui-slider-handle");
	}
	
	function doSlide(e, ui){
		var target = $(e.target).prev(".scroll-content"),
		// If sliders were above the content instead of below, we'd use:
		// target = $(e.target).next(".scroll-content")
		maxScroll = target.attr("scrollWidth") - target.width();
		
		// Need to check type now to prevent the new change handler from firing twice when user clicks on slider,
		// because both 'slide' and 'change' events are fired on a click, but only a 'change' when setting slider
		// value manually via code.
		if (e.type == 'slide'){
			// Was it a click or drag?
			if (slideDrag === true){
				// User dragged slider head, match position
				target.attr({scrollLeft: ui.value * (maxScroll / slideWidth) });
			}
			else{
				// User clicked on slider itself, animate to position
				target.stop().animate({scrollLeft: ui.value * (maxScroll / slideWidth) }, slideSpeed);
			}
			animated = true;
		}
		else{
			if (animated === false){
				target.stop().animate({scrollLeft: ui.value * (maxScroll / slideWidth) }, slideSpeed);
			}
			animated = false;
		}
	}
	
});

//TYPEWRITER TEXT
$(document).ready(function(){
	var ch = 0;
	var item = 0;
	var items = $('#caption li').length;
	var time = 3000;
	var delay = 40;
	var wait = 2000

	$('#showCaption').css('width', ($('#caption').width() + 25));

	function tickInterval() {
		if(item < items) {
			var text = $('#caption li:eq('+item+')').text();
			type(text);
			text = null;
			var tick = setTimeout(tickInterval, time);			
		} else {
			clearTimeout(tick);
		}
	}

	function type(text) {
		time = delay;
		$('#showCaptionText').html(text.substr(0, ch++));
		if(ch > text.length) {
			item++;
			ch = 0;
			time = wait;
		}	
	}
	var tick = setTimeout(tickInterval, time);
});

//FORM BLUR FIELDS
$(document).ready(function(){ 
        $(".wpcf7-form input").focus(function () { 
  $(this).val(""); 
  }).blur(function() { 
                if ($(this).val() == "") { 
                        $(this).val($(this)[0].defaultValue); 
                } 
        }); 
}); 
$(document).ready(function(){ 
        $(".wpcf7-form textarea").focus(function () { 
  $(this).val(""); 
  }).blur(function() { 
                if ($(this).val() == "") { 
                        $(this).val($(this)[0].defaultValue); 
                } 
        }); 
});
$(document).ready(function(){ 
        $("#mc-embedded-subscribe-form").focus(function () { 
  $(this).val(""); 
  }).blur(function() { 
                if ($(this).val() == "") { 
                        $(this).val($(this)[0].defaultValue); 
                } 
        }); 
}); 
$(document).ready(function(){ 
        $("#mc-embedded-subscribe-form").focus(function () { 
  $(this).val(""); 
  }).blur(function() { 
                if ($(this).val() == "") { 
                        $(this).val($(this)[0].defaultValue); 
                } 
        }); 
}); 

//BLINKING CURSOR
$(document).ready(function(){
function blink(selector){
$(selector).fadeOut('slow', function(){
    $(this).fadeIn('slow', function(){
        blink(this);
    });
});
}

blink('.blinker');
return false;
});

//FANCYBOX
$("a#fancybox").fancybox();

