/*
    GATEWAY JS/CORE
    Copyright (c) 2009, Ernesto Mendez
    http://der-design.com
*/

$(document).ready(function() {
    initialize();
    hover_events();
    cub3r_init();
	init_forms();
});

function initialize() {
    // Get the Theme
    theme = $('meta[name=gateway-color]').attr('content');

	// Internet Explorer 6 Fixes
	if (IE6) {
		DD_belatedPNG.fix(".png, ul.check li");
		$('ul#navigation li').dropdown();
	}
    
	// Alternating Colors for menu items
	$("ul#navigation li").find("ul:first").children("li").children("a:even").addClass('alt');

	// Add ID's to portfolio items
	var counter = 1; $('#portfolio .thumbs .thumb').each(function() {$(this).attr('id', 'thumb-' + counter);counter += 1;});
	$('#back-to-top').top_animation('easeInOutExpo', 800);

	// Setup Hover Elements
	if (!IE) {
		$('#featured .separators .pause').css({'visibility':'visible', 'display':'block'});
		$('#portfolio .wrap .thumbs .thumb .hover a img.top, #portfolio .wrap .thumbs .thumb .hover .heading, #featured .separators .pause').css('opacity','0');
	}

	// Prettyphoto Configuration
	$("a[rel^='lightbox']").prettyPhoto({
		animationSpeed: 'normal',
		padding: 40,
		opacity: 0.40,
		showTitle: true,
		allowresize: true,
		counter_separator_label: '/',
		theme: 'light_square',
		hideflash: false,
		modal: false,
		changepicturecallback: function(){},
		callback: function(){}
	});

    // Support for target="_blank"
    $('a[rel=_blank]').attr('target','_blank');

}

function hover_events() {
	$.fn.toggleThumb = function(animList, duration) {
		var id = $(this).attr('id');
		var selector = '#' + id + ' img.top, #' + id + ' .heading';
		$(selector).stop().animate(animList, duration);
	}

	$.fn.toggleThumbIE = function(show) {
		var id = $(this).attr('id');
		var selector = '#' + id + ' img.top, #' + id + ' .heading';
		if (show) {$(selector).show()} else {$(selector).hide()}
	}

	// Portfolio Thumbs
	if (!IE) {
		$('#portfolio .thumbs .thumb .hover, #portfolio .thumbs img.top, #portfolio .thumbs .heading').css('display','block');
		$('#portfolio .thumbs .thumb').hover(function() {
			$(this).toggleThumb({'opacity':'1'},500);
		}, function() {
			$(this).toggleThumb({'opacity':'0'},300);
		});
	} else {
        $('#portfolio .thumbs .thumb .hover').show();
		$('#portfolio .thumbs .thumb').hover(function() {
			$(this).toggleThumbIE(true);
		}, function() {
			$(this).toggleThumbIE(false);
		});
	}

	// Portfolio Sidebar Widget
	if (!IE) {
		$('#portfolio-widget .thumbs .thumb a.hover').css({'opacity':'0', 'display':'block'}).hover(function() {
			$(this).stop().animate({'opacity':'1'},500);
		},function() {
			$(this).stop().animate({'opacity':'0'},300);
		});
	} else {
		$('#portfolio-widget .thumbs .thumb li').hover(function() {
            $(this).parent().find('.hover').show();
		}, function() {
			$(this).parent().find('.hover').hide();
		});
	}

	// Dropdown Menu
	$('ul#navigation li').hover(function() {
		$(this).find('ul:first').css({visibility: 'visible',display: 'none'}).slideDown(400,'easeOutQuart');
	}, function() {
		$(this).find('ul:first').css({visibility: 'hidden'});
	});

}

function cub3r_init() {
	if ( $('#cub3r').length == 0 ) {return false;}
	var flashvars = {};
	flashvars.xml = "assets/images/cu3er/config.xml";
	var attributes = {};
	attributes.wmode = "transparent";
	attributes.id = "slider";
	swfobject.embedSWF("assets/images/cu3er/cu3er.swf", "cub3r", "860", "332", "9", "assets/images/cu3er/expressInstall.swf", flashvars, attributes);
}
