function externalLinks ()
{
	$("a[rel*='external']").attr('target','_blank');
}

function socialMediaEnhancement () {
	$('a#printPage').click( function () {
		window.print();
		return false;
	});
	$('a#paginaFavorita').click( function () {
		alert('Trebuie facuta functia de add to favorites!');
		return false;
	});
	$('a#socialMedia').click( function () {
		alert('Trebuie facuta functia de social bookmarking!');
		return false;
	});
}

function navigationEnhancement () {

	$("a[href^='#']").click(function () {
		var locatie = $(this).attr('href').substring(1);
		if ( locatie != '' ) $.scrollTo( '#'+locatie, 1500 );
		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');
			});
		});
	}
	
	$('.Favicons a[href][title]').qtip({
		content: {
			text: false
		},
		position: {
			corner: {
				tooltip: 'bottomRight',
				target: 'topLeft'
			}
		},
		style: {
			border: {
				width: 1,
				radius: 0,
				color : '#000000'
			},
			padding: 3,
			background: '#ffffff',
			color: '#000000',
			textAlign: 'center',
			tip: true,
			name: 'cream'
		}
	});

}

function categoryEnhancement () {

	$('.Inchis ul').hide();
	
	$('a.Switch').click(function () {
		var status = $(this).parent();
		if ( status.hasClass('Inchis') )
		{
			$(this).parent().removeClass('Inchis').addClass('Deschis');
			$(this).parent().find('ul').slideDown(500);
		}
		else if ( status.hasClass('Deschis') )
		{
			$(this).parent().removeClass('Deschis').addClass('Inchis');
			$(this).parent().find('ul').slideUp(300);
		}
		return false;
	});

}

function inputEnhancement () {

	var defaultSearch;
	//$('#q').val(defaultSearch);
	$('#q').focus(function() {
		if ( $(this).val() == defaultSearch )
		{
			$(this).val('');
		}
	});
	$('#q').blur(function() {
		if ( $(this).val() == '' )
		{
			$(this).val(defaultSearch);
		}
	});
	
	var defaultNL = 'Adresa ta de E-Mail...';
	$('#nlMail').val(defaultNL);
	$('#nlMail').focus(function() {
		if ( $(this).val() == defaultNL )
		{
			$(this).val('');
		}
	});
	$('#nlMail').blur(function() {
		if ( $(this).val() == '' )
		{
			$(this).val(defaultNL);
		}
	});
	
	var defaultNLname = 'Numele tau ...';
	$('#nlName').val(defaultNLname);
	$('#nlName').focus(function() {
		if ( $(this).val() == defaultNLname )
		{
			$(this).val('');
		}
	});
	$('#nlName').blur(function() {
		if ( $(this).val() == '' )
		{
			$(this).val(defaultNLname);
		}
	});
	
	var defaultKW = 'Cauta in e-oferta.ro ...';
	$('#opKeywords').val(defaultKW);
	$('#opKeywords').focus(function() {
		if ( $(this).val() == defaultKW )
		{
			$(this).val('');
		}
	});
	$('#opKeywords').blur(function() {
		if ( $(this).val() == '' )
		{
			$(this).val(defaultKW);
		}
	});
	
	var defaultKW2 = 'Introdu cuvinte cheie...';
	$('#filtru-keywords').val(defaultKW2);
	$('#filtru-keywords').focus(function() {
		if ( $(this).val() == defaultKW2 )
		{
			$(this).val('');
		}
	});
	$('#filtru-keywords').blur(function() {
		if ( $(this).val() == '' )
		{
			$(this).val(defaultKW2);
		}
	});

}

function sifrEnhancement () {

	var chaparral = { src: 'http://e-oferta.ro/themes/original/js/chaparral.swf' };
	// sIFR.useStyleCheck = true;
	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,
		wmode : 'transparent',
		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 : false
	});
	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
	});

}

function inchidereAlerte () {

	$('#alert-close').click(function () {
		$('#alertContainer').slideUp(1000);
		return false;
	});

}

function userPanelEnhancement () { /* Se poate retine starea prin Cookie... */

	$('#cont-lista h2 a').click(function() {
		if ( $(this).parent().parent().hasClass('Deschis') )
		{
			$(this).parent().parent().removeClass('Deschis').addClass('Inchis').find('ul').slideUp(500);
		}
		else if ( $(this).parent().parent().hasClass('Inchis') )
		{
			$(this).parent().parent().removeClass('Inchis').addClass('Deschis').find('ul').slideDown(500);
		}
	});

}

function premiumEnhancement () {

	$('.PremiumBox').hide();
	
	$("h3[id^='premium-'] a").click( function () {
		var vizata = $(this).parent().attr('id').substring(8);
		if ( !$(this).parent().hasClass('Active') )
		{
			$('.PremiumBox:visible').slideUp(300);
			$('h3').removeClass('Active');
			$('#box-'+vizata).slideDown(1000, function() {
				$.scrollTo('#premium-'+vizata,500);
			});
			$(this).parent().addClass('Active');
		}
		else
		{
			$('.PremiumBox:visible').slideUp(300);
			$('h3').removeClass('Active');
		}
		return false;
	});
	
	var i = 0;
	$('#box-deCeMerita tbody tr').each( function () {
		i++;
		if ( !(i%2) )
		{
			$(this).addClass('Even');
		}
	});

}

function statisticiEnhancement () {

	$('.InfoMare').hide();
	$('.InfoInchide').hide();
	
	$('a.InfoDeschide').click( function () {
	
		IDul = Number($(this).attr('id').substring(8));
		$('#mare-'+IDul).slideDown(500);
		$(this).hide();
		$('#inchide-'+IDul).show();
		return false;
	
	});
	
	$('a.InfoInchide').click( function () {
	
		IDul = Number($(this).attr('id').substring(8));
		$('#mare-'+IDul).slideUp(200);
		$(this).hide();
		$('#extinde-'+IDul).show();
		return false;
	
	});

}

function sliderEnhancement ()
{
	$('#loopedSlider').loopedSlider({
		autoHeight: 337,
		autoStart: 4000,
		restart: 8000
	});
}

function LPenhancement ()
{

	// preload
	if ( location.hash == '#promovare' )
	{
		$('#titluLPclienti').hide();
		$('#LPclienti').hide();
		$('#titluLPpromovare').show();
		$('#LPpromovare').show();
		$('a[href="#promovare"]').parent().addClass('Active');
		$('a[href="#clienti"]').parent().removeClass('Active');
	}

	$('#lp').find('a[href="#promovare"]').click(function ()
	{
		//var pagina = $(this).attr('href').substring(1);
		var activ = $(this).parent().hasClass('Active');
		if ( !activ )
		{
			$('#titluLPclienti').slideUp(1000);
			$('#LPclienti').slideUp(1000);
			$('#titluLPpromovare').slideDown(1000);
			$('#LPpromovare').slideDown(1000, function ()
			{
				location.hash = '#promovare';
			});
			$(this).parent().addClass('Active');
			$('a[href="#clienti"]').parent().removeClass('Active');
		}
		return false;
	});
	
	$('#lp').find('a[href="#clienti"]').click(function ()
	{
		var activ = $(this).parent().hasClass('Active');
		if ( !activ )
		{
			$('#titluLPpromovare').slideUp(1000);
			$('#LPpromovare').slideUp(1000);
			$('#titluLPclienti').slideDown(1000);
			$('#LPclienti').slideDown(1000, function ()
			{
				location.hash = '#clienti';
			});
			$(this).parent().addClass('Active');
			$('a[href="#promovare"]').parent().removeClass('Active');
		}
		return false;
	});
}

// Titluri cu font alternativ
sifrEnhancement();


//window.onload = setScreenClass; 
//window.onresize = setScreenClass;
//
//function setScreenClass ()
//{
//	//	class name			screen width
//	//	------------------------------------------
//	//	handheld			240px	-	479px
//	//	small				480px	-	1067px
//	//	standard			1068px	-	1280px
//	//	wide				1281px	-	infinit
//
//	var fmt = document.documentElement.clientWidth;
//	var cls = (fmt<=479)?'handheld':(fmt>479&&fmt<=1067)?'small':(fmt>1067&&fmt<=1280)?'standard':'wide';
//	document.body.className = cls;
//	
//	/* cod de handheld */
//	var el = document.getElementsByTagName("link");
//	if ( cls == 'handheld' && ( el[0].href.indexOf('css/handheld.css') == -1 ) )
//	{
//		el[0].href = 'http://supercazare.ro/eoferta/themes/original/css/handheld.css';
//	}
//	else if ( el[0].href.indexOf('css/e-oferta.css') == -1 )
//	{
//		el[0].href = 'http://supercazare.ro/eoferta/themes/original/css/e-oferta.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();
	
	// Procesarea actiunilor de alerte
	inchidereAlerte();
	
	// Efectele de expandare a categoriilor
	categoryEnhancement();
	
	// Efectele de expandare a meniului din "contul meu"
	userPanelEnhancement();
	
	// Efectele de expandare a tab-urilor din prezentarea Premium
	//premiumEnhancement();
	
	// Efectele de expandare a detaliilor comenzilor din statistici cont
	statisticiEnhancement();
	
	// Efectele de slider
	sliderEnhancement();
	
	// Efectele de schimbare a tab-ului in landing page
	LPenhancement();
	
	// Functiile de social media
	socialMediaEnhancement();

});