function externalLinks () {

	$("a[rel*='external']").attr('target','_blank');

}

function socialMediaEnhancement () {

	$('a#printPage').click( function () {
		window.print();
		return false;
	});

}

function navigationEnhancement () {

	// scrollTo generic
	$("a[href^='#']").click(function () {
		var locatie = $(this).attr('href').substring(1);
		if ( locatie != '' ) $.scrollTo( '#'+locatie, 1500 );
		return false;
	});

	// functionalitatea meniului lateral
	$('#sideMenu h3 a').click(function () {
		var deDeschis = $(this).attr('id').substring(5);
		if ( deDeschis && deDeschis != '' && deDeschis.length > 1 )
		{
			var box = $('#l-'+deDeschis+' .SideSubmeniu');
			if ( box )
			{
				if ( !box.is(':visible') )
				{
					$('#sideMenu ul li[id^="l-"] .SideSubmeniu:visible').slideUp('500', function () {
						$(this).parent().removeClass('Active');
					});
					box.slideDown('500', function () {
						$(this).parent().addClass('Active');
					});
				}
				else
				{
					box.slideUp('500', function () {
						$(this).parent().removeClass('Active');
					});
				}
			}
		}
		return false;
	});

}

function effectsEnhancement () {

	$('#overlay').fadeTo(1,0.6);
	
	if ( jQuery.browser.msie && parseInt(jQuery.browser.version) == 6 ) {
		$(function() {
			$('button,input,select,textarea,li,button').hover(function() {
				$(this).addClass('hover');
			}, function() {
				$(this).removeClass('hover');
			});
			$('button,input,select,textarea,button').focus(function() {
				$(this).addClass('focus');
			});
			$('button,input,select,textarea,button').blur(function() {
				$(this).removeClass('focus');
			});
		});
	}

}

function inputEnhancement () {

	var defaultSearch = 'Cauta acum...';
	$('#q').val(defaultSearch);
	$('#q').focus(function() {
		if ( $(this).val() == defaultSearch )
		{
			$(this).val('');
		}
	});
	$('#q').blur(function() {
		if ( $(this).val() == '' )
		{
			$(this).val(defaultSearch);
		}
	});
	
	var defaultNL = 'Introdu mail-ul tau aici...';
	$('#newsletter').val(defaultNL);
	$('#newsletter').focus(function() {
		if ( $(this).val() == defaultNL )
		{
			$(this).val('');
		}
	});
	$('#newsletter').blur(function() {
		if ( $(this).val() == '' )
		{
			$(this).val(defaultNL);
		}
	});
	
	$('#form-rata input[type="radio"]').change( function () {
		if ( $(this).is(':checked') )
		{
			$('#l-rata-moneda-eur, #l-rata-moneda-ron').removeClass('Active');
			var nume = $(this).attr('id');
			$('#l-'+nume).addClass('Active');
		}
	});

}

function sifrEnhancement () {

	var chaparral = { src: 'js/chaparral.swf' };
	sIFR.activate(chaparral);
	sIFR.replace(chaparral, {
		selector : '#content h2.sIFR',
		css: [
			'.sIFR-root { background-color : #f3f3f3; color : #000000; font-size : 18px; text-transform : uppercase; font-weight : bold; }',
			'a { text-decoration : none; color : #000000; }',
			'a:link { color : #000000; }',
			'a:hover { color : #ff0000; }'
		],
		offsetTop : 5,
		forceSingleLine : true
	});
	sIFR.replace(chaparral, {
		selector : '#content h2.sIFRRosu',
		css: [
			'.sIFR-root { background-color : #ffe7e7; color : #000000; font-size : 18px; text-transform : uppercase; font-weight : bold; }',
			'a { text-decoration : none; color : #000000; }',
			'a:link { color : #000000; }',
			'a:hover { color : #ff0000; }'
		],
		offsetTop : 5,
		forceSingleLine : true
	});
	sIFR.replace(chaparral, {
		selector : '#content h2.sIFRAlb',
		css: [
			'.sIFR-root { leading : -8; background-color : #ffffff; color : #000000; font-size : 18px; font-weight : bold; }',
			'a { text-decoration : none; color : #000000; }',
			'a:link { color : #000000; }',
			'a:hover { color : #ff0000; }'
		],
		offsetTop : 0,
		tuneHeight : -10,
		forceSingleLine : false
	});
	sIFR.replace(chaparral, {
		selector : '#facilitati h3',
		css: [
			'.sIFR-root { leading : -5; background : #f3f3f3; color : #000000; text-transform : uppercase; font-weight : bold; }'
		],
		wmode : 'transparent',
		offsetTop : 0,
		tuneHeight : 0,
		forceSingleLine : true
	});
	sIFR.replace(chaparral, {
		selector : '.Stat .sIFR',
		css: [
			'.sIFR-root { leading : -5; color : #0d743b; font-weight : bold; letter-spacing : -1; font-size: 27px; }'
		],
		wmode : 'transparent',
		offsetTop : -4,
		tuneWidth : 0,
		tuneHeight : -15,
		forceSingleLine : true
	});
	sIFR.replace(chaparral, {
		selector : 'h1#titluSectiune',
		css: [
			'.sIFR-root { leading : -13; color : #000000; font-weight : bold; letter-spacing : -1; text-transform : uppercase; font-size: 36px; }'
		],
		wmode : 'transparent',
		offsetTop : 0,
		tuneWidth : 0,
		tuneHeight : -5,
		forceSingleLine : true
	});
	sIFR.replace(chaparral, {
		selector : 'h1#titluCategorie, h1#titluCatDirector, h1#titluCompanie, h1#titluCautare',
		css: [
			'.sIFR-root { leading : -13; color : #000000; font-weight : bold; letter-spacing : -1; font-size: 36px; }'
		],
		wmode : 'transparent',
		offsetTop : -9,
		tuneWidth : 0,
		tuneHeight : -18
	});
	sIFR.replace(chaparral, {
		selector : 'h1#titluDirector',
		css: [
			'.sIFR-root { leading : -13; color : #000000; font-weight : bold; letter-spacing : -1; text-transform : uppercase; font-size: 36px; }'
		],
		wmode : 'transparent',
		offsetTop : -9,
		tuneWidth : 0,
		tuneHeight : -18
	});
	sIFR.replace(chaparral, {
		selector : 'h1#titluCreareCont, h1#titluCont, h1#titluProdus, h1#titluStire',
		css: [
			'.sIFR-root { leading : -13; color : #000000; font-weight : bold; letter-spacing : -1; font-size: 36px; }'
		],
		wmode : 'transparent',
		offsetTop : -9,
		tuneWidth : 0,
		tuneHeight : -15,
		forceSingleLine : true
	});
	sIFR.replace(chaparral, {
		selector : 'h2.sIFR-Poll',
		css: [
			'.sIFR-root { leading : -6; color : #000000; font-weight : bold; letter-spacing : -1; font-size: 18px; }'
		],
		wmode : 'transparent',
		offsetTop : -4,
		tuneWidth : 0,
		tuneHeight : -8
	});

}

// Titluri cu font alternativ
//sifrEnhancement();

// Clase diferite pentru rezolutii diferite
window.onload = setScreenClass; 
window.onresize = setScreenClass;

function setScreenClass ()
{
	//	class name			screen width
	//	------------------------------------------
	//	w-handheld			240px	-	479px
	//	w-small			480px	-	949px
	//	w-oldstandard		950px	-	1067px
	//	w-standard			1068px	-	1280px
	//	w-wide			1281px	-	infinit

	var fmt = document.documentElement.clientWidth;
	var cls = (fmt<=479)?'w-handheld':(fmt>479&&fmt<=949)?'w-small':(fmt>949&&fmt<=1067)?'w-oldstandard':(fmt>1067&&fmt<=1280)?'w-standard':'w-wide';
	if ( $('body').attr('class').indexOf('w-') != -1 )
	{
		$('body').removeClass('w-handheld').removeClass('w-small').removeClass('w-oldstandard').removeClass('w-standard').removeClass('w-wide');
	}
	$('body').addClass(cls);
	
	/* cod de handheld */
	var el = document.getElementsByTagName("link");
	if ( cls == 'w-handheld' && ( el[0].href.indexOf('handheld.css') == -1 ) )
	{
		el[0].href = 'css/handheld.css';
	}
	else if ( el[0].href.indexOf('platinum.css') == -1 )
	{
		el[0].href = 'css/platinum.css';
	}
}

$(document).ready(function () {

	// Navigare imbunatatita cu efecte
	navigationEnhancement();
	
	// Input-uri
	inputEnhancement();
	
	// trigger pentru lightbox
	$(".lightbox").lightbox();

	// Opacitati si efecte
	effectsEnhancement();

	// Link-uri externe
	externalLinks();
	
	// Functiile de social media
	socialMediaEnhancement();

});