/**
 *
 * Author: Serkan Sökmen
 * Benartı Software Solutions
 *
 */


// STYLING FILE INPUTS 1.0 | Shaun Inman <http://www.shauninman.com/> | 2007-09-07
if (!window.SI) { var SI = {}; };
SI.Files =
{
	htmlClass : 'SI-FILES-STYLIZED',
	fileClass : 'file',
	wrapClass : 'cabinet',

	fini : false,
	able : false,
	init : function()
	{
		this.fini = true;

		var ie = 0 //@cc_on + @_jscript_version
		if (window.opera || (ie && ie < 5.5) || !document.getElementsByTagName) { return; } // no support for opacity or the DOM
		this.able = true;

		var html = document.getElementsByTagName('html')[0];
		html.className += (html.className != '' ? ' ' : '') + this.htmlClass;
	},

	stylize : function(elem)
	{
		if (!this.fini) { this.init(); };
		if (!this.able) { return; };

		elem.parentNode.file = elem;
		elem.parentNode.onmousemove = function(e)
		{
			if (typeof e == 'undefined') e = window.event;
			if (typeof e.pageY == 'undefined' &&  typeof e.clientX == 'number' && document.documentElement)
			{
				e.pageX = e.clientX + document.documentElement.scrollLeft;
				e.pageY = e.clientY + document.documentElement.scrollTop;
			};

			var ox = oy = 0;
			var elem = this;
			if (elem.offsetParent)
			{
				ox = elem.offsetLeft;
				oy = elem.offsetTop;
				while (elem = elem.offsetParent)
				{
					ox += elem.offsetLeft;
					oy += elem.offsetTop;
				};
			};

			var x = e.pageX - ox;
			var y = e.pageY - oy;
			var w = this.file.offsetWidth;
			var h = this.file.offsetHeight;

			this.file.style.top		= y - (h / 2)  + 'px';
			this.file.style.left	= x - (w - 30) + 'px';
		};
	},

	stylizeById : function(id)
	{
		this.stylize(document.getElementById(id));
	},

	stylizeAll : function()
	{
		if (!this.fini) { this.init(); };
		if (!this.able) { return; };

		var inputs = document.getElementsByTagName('input');
		for (var i = 0; i < inputs.length; i++)
		{
			var input = inputs[i];
			if (input.type == 'file' && input.className.indexOf(this.fileClass) != -1 && input.parentNode.className.indexOf(this.wrapClass) != -1)
			{
				this.stylize(input);
			};
		};
	}
};

var gsi =
{	
	// Animation Speed
	speed			: 400,
	
	// Sub Menu Actions
	showSub		: function(link)
	{
		$(link).find('ul').slideDown(this.speed);
	},
	hideSub		: function(link)
	{
		$(link).find('ul').slideUp(this.speed);
	},
	
	// Search Widget
	searchWidget			: null,
	inputField				: null,
	submitButton			: null,
	optionsPane				: null,
	bMouseOverSearch 	: false,
	initSearchWidget	: function(selector)
	{
		this.searchWidget = $(selector);
		this.inputField		= this.searchWidget.find('input#search');
		this.submitButton = this.searchWidget.find('input.searchicon');
		this.optionsPane	= this.searchWidget.find('.options')
		gsi.hideSearchOptions();
		this.inputField.focus(function(event)
		{
			gsi.showSearchOptions();
			gsi.hideInputPlaceholder();
		});
		this.inputField.blur(function()
		{
			if (!gsi.bMouseOverSearch)
			{
				gsi.hideSearchOptions();
				gsi.refreshInputPlaceholder();
			}
		});
		this.optionsPane.hover(function(){gsi.bMouseOverSearch = true;}, function(){gsi.bMouseOverSearch = false;});
		this.submitButton.click(function(e)
		{
			gsi.hideSearchOptions();
			gsi.refreshInputPlaceholder();
		});
	},
	
	showSearchOptions	: function(input)
	{
		$(input).addClass('withtext').removeClass('withouttext');
		this.optionsPane.slideDown(this.speed);
		this.optionsPane.prev('.arrow').fadeIn(this.speed);
	},
	
	
	hideSearchOptions	: function(input)
	{
		this.optionsPane.slideUp(this.speed);
		this.optionsPane.prev('.arrow').fadeOut(this.speed);
	},
	
	refreshInputPlaceholder : function()
	{
		if (this.inputField.val().length == 0)
			this.inputField.removeClass('withtext').addClass('withouttext');
		else
			this.inputField.removeClass('withouttext').addClass('withtext');
	},
	hideInputPlaceholder : function()
	{
		this.inputField.removeClass('withouttext').addClass('withtext');
	}
}


$(document).ready(function()
{
	gsi.initSearchWidget('#searchwidget');
	
	$("#frPosition").change(function(){
		var posval = $(this).val();
		if(posval == 4){$('#otherpos').show();}else{$('#otherpos').hide();}
	});
	
	$('#mainnav li').hoverIntent(function(e)
	{
		gsi.showSub(this);
	}, function()
	{
		gsi.hideSub(this);
	});
	
	if ($('html').hasClass('ie8') || $('html').hasClass('ie7'))
	{
		$('.button.rounded10, .back.rounded10').removeClass('rounded10')
												.before('<div class="sprite roundleft"/>')
												.after('<div class="sprite roundright"/>')
												.css(
													{
														'float' 	: 'left',
														'height'	: '20px'
													});
		$('input.textinput, input.submit').removeClass('rounded10')
												.before('<div class="sprite roundleft"/>')
												.after('<div class="sprite roundright"/>')
												.css(
												{
													'float' 		: 'left',
													'height'		: '24px',
													'padding'		: 0
												});
	}
	
	
	if ($('#screen .tabs').length > 0)
	{
		$('#screen .tabs').tabs('div.panes img', {
			effect				: 'fade',
			fadeOutSpeed	: 'slow',
			rotate				: true
		}).slideshow({
			interval	: 3000,
			clickable	: true,
			autoplay	: true
		});
		var hPosControls = setTimeout(function()
		{
			var el 		= $('#screen .controls');
			var pleft = parseInt(el.css('padding-left').substr(0, el.css('padding-left').length-2));
			var mleft = ((el.parent().width() - el.width()) / 2) - pleft;
			el.css('left', mleft + 'px');
			el.fadeIn(gsi.speed);
			clearTimeout(hPosControls);
		}, 100);	
	}
	
	if ($('.right ul.ntabs li').length == 1)
	{
		$('.right ul.ntabs').remove();
	}
	else
	{
		if ($('.right .scrollable').length > 0)
		{
			$('.right ul.ntabs').tabs('.scrollable > .items > div', {
				effect				: 'fade',
				rotate				: false
			});	
		}
		if ($('.right .blockscrollable').length > 0)
		{
			$('.right ul.ntabs').tabs('.blockscrollable > .items > .block', {
				effect				: 'fade',
				rotate				: false
			});	
		}	
	}
	
	// Collection
	if ($('.right ul.coltabs').length > 0)
	{
		if ($('.right .colpanes').length > 0)
		{
			$('.right ul.coltabs').tabs('.colpanes > div', {
				effect				: 'fade',
				rotate				: false
			});	
		}
	}
	$('.imgzoom').each(function()
	{
		$(this).addimagezoom({
			magnifiersize			: [600, 400],
			magnifierpos			: 'right',
			largeimage				: $(this).data('largeimg'),
			cursorshade				: true,
			cursorshadecolor	: '#fff',
			cursorshadeborder	: '1px solid white',
			left							: '200px'
		});
	});
	
	// File input styler
	if ($('input[type="file"]').length > 0)	SI.Files.stylizeAll();
	
	Shadowbox.init(
	{
		overlayColor		: '#000',
		overlayOpacity	: .8,
		modal						: false,
		displayNav			: false
	});
	
	$('#teambanner a').live('click', function(e)
	{
		$.ajax({
			url				: MEMBER_URL + $(this).attr('rel'),
			type			: 'POST',
			dataType	: 'html',
			success		: function (response)
			{
				if(response)
				{
					Shadowbox.open(
					{
						player	: 'html',
						content	: response,
						width		: 300
					});
				}
			},
			error		: function (data, error)
			{
				return false;
			}
		});
		return false;
	});
	
	$('a.disclaimer').live('click', function(e){
		
		$.ajax({
			url				: CONTENT_URL + $(this).attr('rel'),
			type			: 'POST',
			dataType	: 'html',
			success		: function (response)
			{
				if(response)
				{
					Shadowbox.open(
					{
						player	: 'html',
						content	: response,
						width	: 640
					});
				}
			},
			error		: function (data, error)
			{
				return false;
			}
		});
		return false;
	});
});

