/* 
	Theme Name: Premium Portfolio
	Description: Premium Portfolio for ThemeForest
	Author: Innovatics GmbH
	Author URI: http://www.innovatics.de/
	Version: 1.0
*/

document.write('<script type="text/javascript" src="js/cufon-yui.js"></script>');     
document.write('<script type="text/javascript" src="js/eras.font.js"></script>');
document.write('<script type="text/javascript" src="js/jquery.validate.min.js"></script>');
document.write('<script type="text/javascript" src="js/jquery.tools.min.js"></script>');
document.write('<script type="text/javascript" src="js/jquery.scrollTo-1.4.2-min.js"></script>');
document.write('<script type="text/javascript" src="js/hoverIntent.js"></script>');
document.write('<script type="text/javascript" src="js/superfish.js"></script>');
 
// Not necessary for the theme - only for preview
document.write('<script type="text/javascript" src="js/jquery.cookie.js"></script>');
 
$(document).ready(function() {
	/********************************************************************************/
	// Not necessary for the theme - only for preview
	
	// "color-switcher" animation
	if($.cookie('color-toggle') == null)
		$.cookie('color-toggle', 1);
	
	$('#color-switcher').attr('style', $.cookie('color-toggle') == 1 ? 'height: 0px' : 'height: 150px');
	$('#color-slider').attr('style', $.cookie('color-toggle') == 1 ? 'height: 35px' : 'height: 184px');
	
	$('#color-slider').live('click', function() {
		$('#color-switcher').animate({height: $.cookie('color-toggle') == 0 ? '0px' : '150px'}, 'slow');
		$(this).animate({height: $.cookie('color-toggle') == 0 ? '35px' : '184px'}, 'slow');
		
		$.cookie('color-toggle', $.cookie('color-toggle') == 0 ? 1 : 0);
	});
	
	// set a cookie for the "color-switcher"
	$('#color-switcher .color-box img').live('click', function() {
		if($(this).is('img'))
			$.cookie('premiumcolor', $(this).attr('alt'));
		else
			$.cookie('premiumcolor', 'blue');
			
		$.cookie('color-toggle', 1);
		window.location.reload();
	});
  	
  	// load the color stylesheet
  	$('link[rel=stylesheet][title]').each(function(i) {
		if($.cookie('premiumcolor') != null)
		{
			if($(this).attr('title') == 'premiumcolor')
				$(this).attr('href', 'css/premium-' + $.cookie('premiumcolor') + '.css');
			if($(this).attr('title') == 'premiumcolor-ie')
				$(this).attr('href', 'css/premium-' + $.cookie('premiumcolor') + '-ie.css');
			
			// cufon	
			if($.cookie('premiumcolor') == 'orange')
				Cufon.replace('.content .box-white .eras', { color: '#da7927' });
			else if($.cookie('premiumcolor') == 'green')
				Cufon.replace('.content .box-white .eras', { color: '#a3a341' });
		}
	});
	
	/********************************************************************************/
	
	// cufon
	Cufon.replace('.eras');
	
	// dropdown menu - based on superfish
	$("ul.main").superfish({
		hoverClass: 'hover',
		delay: 0,
		animation: {height: 'show'},
		autoArrows: false, 
  		dropShadows: false
	});
	
	// slider one - based on jquery tools scrollable
	if($('.slider-one').is('div'))
	{
		$('.slider-one-navi #point1').addClass('active');
	
		$(".slider-one").scrollable({ circular: true }).navigator({
			navi: ".slider-one-navi",
			naviItem: 'a',
			activeClass: 'active',
			history: true
		}).autoscroll({ autoplay: true, interval: 10000 });
	}
	
	// opens a link in a new tab
	$('a[href^=http]').click( function() {
		window.open(this.href);
 		return false;
	});
	
	// form input and textarea onfocus/onblur effect
	$('form input[type=text], form textarea').live('focus', function() {
		$('label.overlay[for=' + $(this).attr('id') + ']').hide();
	});
	
	$('form input[type=text], form textarea').live('blur', function() {
		if($(this).val() == '')
			$('label.overlay[for=' + $(this).attr('id') + ']').show();				
	});
	
	// clear all form elements
	$('form button.abort').live('click', function() {
		var form = $(this).parent().parent();
		
		if(form.is('form'))
		{
			$('#' + form.attr('id') + ' input[type=text], #' + form.attr('id') + ' textarea').each(function () {
				$(this).val('');
				$('#' + form.attr('id') + ' label.overlay[for=' + $(this).attr('id') + ']').show();
				$('#' + form.attr('id') + ' label.error').hide();
			});
		}	
	})
	
	// form validation
	$('#form-write-reply').validate();
	$("#form-contact").validate();
	$("#form-quick-contact").validate();
	
	// "go to top" scroll effect
	$('a[href^=#]').click(function() {
        var parts = this.href.split('#');
        
		if(parts[1] != '')
			$.scrollTo('#' + (parts[1] == '' ? 'header' : parts[1]), 800, { axis: 'y' });
    });   	
});
